> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inco.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Contracts, RPC & covalidators

> Map SDK operations to contract calls and signed Lightning requests.

## Which service does what?

| Operation                           | Destination              | Typical mechanism                                                                                             |
| ----------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------- |
| Account access / signatures         | Wallet provider          | `eth_requestAccounts`, typed-data/message signing through viem.                                               |
| Chain identity                      | Wallet or public RPC     | `eth_chainId`.                                                                                                |
| Contract state                      | Public RPC               | `eth_call`, batched Multicall where applicable.                                                               |
| Gas estimation                      | Public RPC / wallet      | `eth_estimateGas`.                                                                                            |
| Transaction submission              | Caller-owned wallet      | Usually `eth_sendTransaction` for JSON-RPC accounts; local/custom signers may submit signed raw transactions. |
| Confirmation / replacement tracking | Public RPC               | Receipts and block/transaction polling through viem.                                                          |
| Encryption / attestation            | Lightning / covalidators | Network discovery, encryption, signed proof requests.                                                         |

RPC sequences depend on your wallet and transport; viem handles these calls.

## Contract mapping

| Contract          | Function                                                                                                                                  | Used by                                                        |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| Wrapper factory   | `getWrapper(address)`                                                                                                                     | Deployed/registered wrapper resolution.                        |
| Wrapper factory   | `computeWrapperAddress(address)`                                                                                                          | Predicted wrapper resolution and pre-approval.                 |
| Wrapper factory   | `createWrapper(address)`                                                                                                                  | `ensureWrapper` / deposit setup.                               |
| Underlying ERC-20 | `decimals()`, `balanceOf(address)`, `allowance(address,address)`, `approve(address,uint256)`                                              | Amount precision, public balance, allowance, approval.         |
| cToken            | `underlying()`, `confidentialBalanceOf(address)`                                                                                          | Reverse lookup and encrypted balance handle.                   |
| cToken            | `wrap(address,uint256)`                                                                                                                   | Shield tokens to owner.                                        |
| cToken            | `confidentialTransfer(address,bytes)` payable overload                                                                                    | Encrypted transfer with ciphertext fee.                        |
| cToken            | `periodOfIncreasingBalanceCounter(address)`, `lastIncomingTransferCounter(address,uint256)`, `balanceCheckpoint(address,uint256,uint256)` | Withdrawal checkpoint selection.                               |
| cToken            | `unwrap(...)`                                                                                                                             | Owner, amount, period, counter, attestation tuple, signatures. |
| Inco executor     | `getFee()`                                                                                                                                | Current ciphertext fee.                                        |
| Session verifier  | `wrapperFactory()` probe on unknown deployments                                                                                           | Determine scoped versus generic verifier dialect.              |

Deposit targets the cToken. For raw reads, declare required functions with viem `parseAbi`; the SDK does not export ABIs.

## Minimal raw read

```ts theme={null}
import { createPublicClient, http, parseAbi } from "viem";
import { baseSepolia } from "viem/chains";

const rpc = createPublicClient({ chain: baseSepolia, transport: http() });
const factory = "0x6f9a0ECD77C3Dade8Dc14a507cAbABFD746575f8";
const token = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";

const wrapper = await rpc.readContract({
  address: factory,
  abi: parseAbi(["function getWrapper(address) view returns (address)"]),
  functionName: "getWrapper",
  args: [token],
});
```

Raw JSON-RPC health example:

```bash theme={null}
curl -sS https://sepolia.base.org \
  -H 'content-type: application/json' \
  --data '{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}'
# Expected Base Sepolia chain ID: 0x14a34
```

Raw writes require amount validation, wrapper/allowance checks, confirmation handling, and Lightning encryption/attestations. The [core transaction methods](/ctoken/transactions) handle these steps.

## Covalidator endpoints

### Discovery and transport

Lightning discovers covalidators for the selected network. RPC URLs come from `publicClient` or `incoRpcUrls`; initialization is lazy.

KMS requests use Lightning’s quorum/retry policy, independent of indexer timeouts.

| Method | Path                                           | Input and result                                                                                                    |
| ------ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| POST   | `/inco.kms.lite.v1.KmsService/IsReady`         | Readiness request `{}`; successful observed response `{ "ready": true }`.                                           |
| POST   | `/inco.kms.lite.v1.KmsService/AttestedDecrypt` | Signed handle/ACL/reencryption request; returns encrypted or plaintext attestation material processed by Lightning. |
| POST   | `/inco.kms.lite.v1.KmsService/AttestedCompute` | Signed operation, lhs handle, rhs value and ACL request; SDK withdrawal uses greater-than-or-equal attestation.     |

## Readiness probe

```bash theme={null}
# Use a covalidator URL discovered for your network.
curl -sS "$COVALIDATOR_URL/inco.kms.lite.v1.KmsService/IsReady" \
  -H 'content-type: application/json' \
  -H 'connect-protocol-version: 1' \
  --data '{}'
```

## Signed request structure

Lightning builds protobuf requests. `AttestedDecrypt`: `userAddress`, `handlesWithProofs`, `eip712Signature`, `reencryptPubKey`. `AttestedCompute`: `userAddress`, `op`, `lhsHandle`, `rhsPlaintext` (hex), `eip712Signature`, `reencryptPubKey`, `aclProof`.

Use Lightning to encode proofs, signatures, session scope, and reencryption keys and verify the quorum. These field lists are not unsigned JSON templates; possessing a handle does not authorize decryption.

Use `decryptHandles()` and `withdraw()` through the SDK. There are no top-level `encrypt()` or `attestedCompute()` methods.
