> For the complete documentation index, see [llms.txt](https://andrewkimjoseph.gitbook.io/celina-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://andrewkimjoseph.gitbook.io/celina-sdk/services/contractservice.md).

# ContractService

[**@andrewkimjoseph/celina-sdk**](/celina-sdk/api-reference/api-reference.md)

***

[@andrewkimjoseph/celina-sdk](/celina-sdk/api-reference/api-reference.md) / [services/contract.service](https://github.com/andrewkimjoseph/celina-sdk/tree/main/docs/api-reference/services/contract.service/README.md) / ContractService

## Class: ContractService

Defined in: [src/services/contract.service.ts:57](https://github.com/andrewkimjoseph/celina-sdk/blob/c35fe1db07a45a3cd14b2185df4abf2e6a2ec609/src/services/contract.service.ts#L57)

Read, gas-estimate, and prepare helpers for arbitrary contracts.

### Constructors

#### Constructor

> **new ContractService**(`clientFactory`): `ContractService`

Defined in: [src/services/contract.service.ts:60](https://github.com/andrewkimjoseph/celina-sdk/blob/c35fe1db07a45a3cd14b2185df4abf2e6a2ec609/src/services/contract.service.ts#L60)

**Parameters**

**clientFactory**

`CeloClientFactory`

**Returns**

`ContractService`

### Methods

#### callFunction()

> **callFunction**(`params`): `Promise`<{ `contractAddress`: `` `0x${string}` ``; `error?`: `undefined`; `functionName`: `string`; `network`: `"mainnet"`; `result`: `unknown`; `success`: `boolean`; } | { `contractAddress`: `` `0x${string}` ``; `error`: `string`; `functionName`: `string`; `network`: `"mainnet"`; `result`: `null`; `success`: `boolean`; }>

Defined in: [src/services/contract.service.ts:69](https://github.com/andrewkimjoseph/celina-sdk/blob/c35fe1db07a45a3cd14b2185df4abf2e6a2ec609/src/services/contract.service.ts#L69)

Simulate a read-only contract call (`eth_call`).

**Parameters**

**params**

[`ContractCallParams`](/celina-sdk/types/contractcallparams.md)

Contract address, ABI, function name, and optional args

**Returns**

`Promise`<{ `contractAddress`: `` `0x${string}` ``; `error?`: `undefined`; `functionName`: `string`; `network`: `"mainnet"`; `result`: `unknown`; `success`: `boolean`; } | { `contractAddress`: `` `0x${string}` ``; `error`: `string`; `functionName`: `string`; `network`: `"mainnet"`; `result`: `null`; `success`: `boolean`; }>

Decoded result on success; `{ success: false, error }` on revert

***

#### estimateGas()

> **estimateGas**(`params`): `Promise`<{ `contractAddress`: `` `0x${string}` ``; `error?`: `undefined`; `functionName`: `string`; `gasEstimate`: `string`; `gasPrice`: `string`; `network`: `"mainnet"`; `success`: `boolean`; `totalCost`: `string`; } | { `contractAddress`: `` `0x${string}` ``; `error`: `string`; `functionName`: `string`; `gasEstimate`: `string`; `gasPrice`: `string`; `network`: `"mainnet"`; `success`: `boolean`; `totalCost`: `string`; }>

Defined in: [src/services/contract.service.ts:114](https://github.com/andrewkimjoseph/celina-sdk/blob/c35fe1db07a45a3cd14b2185df4abf2e6a2ec609/src/services/contract.service.ts#L114)

Estimate gas for a contract call from `fromAddress`.

**Parameters**

**params**

[`ContractCallParams`](/celina-sdk/types/contractcallparams.md) & `object`

Same as `callFunction` plus required `fromAddress`

**Returns**

`Promise`<{ `contractAddress`: `` `0x${string}` ``; `error?`: `undefined`; `functionName`: `string`; `gasEstimate`: `string`; `gasPrice`: `string`; `network`: `"mainnet"`; `success`: `boolean`; `totalCost`: `string`; } | { `contractAddress`: `` `0x${string}` ``; `error`: `string`; `functionName`: `string`; `gasEstimate`: `string`; `gasPrice`: `string`; `network`: `"mainnet"`; `success`: `boolean`; `totalCost`: `string`; }>

Gas estimate, current gas price, and total cost in wei

***

#### prepareFunction()

> **prepareFunction**(`from`, `params`): `Promise`<[`SerializedPreparedFlow`](/celina-sdk/types/serializedpreparedflow.md)>

Defined in: [src/services/contract.service.ts:172](https://github.com/andrewkimjoseph/celina-sdk/blob/c35fe1db07a45a3cd14b2185df4abf2e6a2ec609/src/services/contract.service.ts#L172)

Build an unsigned single-step flow for a contract write (caller ABI). Calldata includes the CELINA attribution suffix. Rejects `view`/`pure` ABI entries.

**Parameters**

**from**

`` `0x${string}` ``

Sender wallet address (must match connected wallet when signing)

**params**

[`ContractCallParams`](/celina-sdk/types/contractcallparams.md)

Contract address, ABI, function name, optional args and wei `value`

**Returns**

`Promise`<[`SerializedPreparedFlow`](/celina-sdk/types/serializedpreparedflow.md)>

Single-step `SerializedPreparedFlow` for wagmi or MCP `executePreparedFlow`


---

# 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://andrewkimjoseph.gitbook.io/celina-sdk/services/contractservice.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.
