> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/api-references/sdk/genericprovider.md).

# GenericProvider

Interface that all provider adapters must implement for chain reads and unsigned transaction preparation.

Interface that all provider adapters must implement for chain reads and unsigned transaction preparation. You only need this if you are building a custom provider -- otherwise use [ViemProvider](/protocol/sdk/api-references/sdk/viemprovider.md), [EthersProvider](/protocol/sdk/api-references/sdk/ethersprovider.md), or the wagmi `createConfig` which builds one internally.

## Import

```ts
import type { GenericProvider } from "@zama-fhe/sdk";
```

## Definition

```ts
interface GenericProvider {
  getChainId(): Promise<number>;
  readContract(config: ReadContractConfig): Promise<unknown>;
  waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt>;
  getBlockTimestamp(): Promise<bigint>;
  prepareTransaction(args: {
    from: Address;
    calldata: WriteContractConfig;
    nonce?: number;
    gasLimit?: bigint;
    fees?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint };
  }): Promise<Hex>;
}
```

## Usage with `createConfig`

Pass a custom provider to the generic `createConfig` from `@zama-fhe/sdk`:

```ts
import { createConfig, ZamaSDK, memoryStorage } from "@zama-fhe/sdk";
import { node } from "@zama-fhe/sdk/node";
import { sepolia } from "@zama-fhe/sdk/chains";

const config = createConfig({
  chains: [sepolia],
  provider: myCustomProvider,
  storage: memoryStorage,
  relayers: { [sepolia.id]: node() },
});
const sdk = new ZamaSDK(config);
```

## Implementing a custom provider

```ts
import type { GenericProvider } from "@zama-fhe/sdk";

class MyProvider implements GenericProvider {
  async getChainId() {
    /* ... */
  }
  async readContract(config) {
    /* ... */
  }
  async waitForTransactionReceipt(hash) {
    /* ... */
  }
  async getBlockTimestamp() {
    /* ... */
  }
  async prepareTransaction(args) {
    /* ... */
  }
}
```

## Methods

### getChainId

```ts
getChainId(): Promise<number>
```

Return the chain ID this provider is connected to.

### readContract

```ts
readContract(config: ReadContractConfig): Promise<unknown>
```

Execute a read-only contract call. `ReadContractConfig` contains `address`, `abi`, `functionName`, and `args`.

### waitForTransactionReceipt

```ts
waitForTransactionReceipt(hash: Hex): Promise<TransactionReceipt>
```

Poll for a transaction receipt by hash.

### getBlockTimestamp

```ts
getBlockTimestamp(): Promise<bigint>
```

Return the timestamp of the latest block.

### prepareTransaction

```ts
prepareTransaction(args: {
  from: Address;
  calldata: WriteContractConfig;
  nonce?: number;
  gasLimit?: bigint;
  fees?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint };
}): Promise<Hex>
```

Build a fully populated, RLP-encoded unsigned EIP-1559 transaction without signing or broadcasting it. The provider reads the chain ID and fills any omitted nonce, gas limit, or fee values from chain state.

## Related

* [ViemProvider](/protocol/sdk/api-references/sdk/viemprovider.md) -- viem implementation
* [EthersProvider](/protocol/sdk/api-references/sdk/ethersprovider.md) -- ethers implementation
* [GenericSigner](/protocol/sdk/api-references/sdk/genericsigner.md) -- wallet authority interface
* [Configuration guide](/protocol/sdk/guides/configuration.md) -- full setup walkthrough


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zama.org/protocol/sdk/api-references/sdk/genericprovider.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
