Skip to content

callContract

Calls a Sophia contract function as an on-chain transaction (stateful call). Used for writing to contract state.

Import

typescript
import { callContract } from '@growae/reactive/actions'

Usage

typescript
import { callContract } from '@growae/reactive/actions'

const result = await callContract(config, {
  address: 'ct_2dATGVvfU1oBShDDsaqfh1sF4bCkx2FKbiCaL2t4zZpMMpMfgE',
  aci: contractAci,
  fn: 'transfer',
  args: ['ak_recipient...', 1000n],
})

Return Type

typescript
type CallContractReturnType = {
  hash: string
  result: unknown
  rawTx: string
}

Parameters

ParameterTypeDefaultDescription
addressstringRequired. Contract address (ct_...).
aciAciRequired. Contract ACI (Application Call Interface).
fnstringRequired. Function name to call.
argsunknown[][]Arguments to pass to the function.
amountbigint0nAE (in aettos) to attach to the call (payable functions).
gasnumberautoGas limit. Auto-estimated if omitted.
gasPricebigintautoGas price in aettos.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.
noncenumberautoAccount nonce.
feebigintautoTransaction fee in aettos.

Default TTL

All transactions default to a TTL of 300 blocks (~15 hours). This prevents stale transactions from lingering indefinitely. Override with ttl: 0 for no expiration.

Examples

Payable contract call

typescript
const result = await callContract(config, {
  address: 'ct_auction...',
  aci: auctionAci,
  fn: 'bid',
  args: [itemId],
  amount: 5000000000000000000n, // 5 AE
})

Custom TTL

typescript
const result = await callContract(config, {
  address: 'ct_token...',
  aci: tokenAci,
  fn: 'transfer',
  args: ['ak_recipient...', 1000n],
  ttl: 0, // no expiration
})

Error Types

typescript
import type { CallContractErrorType } from '@growae/reactive'
  • ConnectorNotConnectedError — no wallet connected
  • ContractCallError — the contract call reverted
  • InsufficientBalanceError — not enough AE for fee + amount