Skip to content

Sophia Contracts

Reactive provides first-class support for deploying and interacting with Sophia smart contracts on Aeternity.

Overview

Sophia is Aeternity's functional smart contract language. Contracts are compiled to bytecode and deployed on-chain. Reactive uses the ACI (Application Call Interface) — a JSON schema describing the contract's functions and types — for type-safe interactions.

Deploying a Contract

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

const result = await deployContract(config, {
  aci: tokenAci,
  bytecode: tokenBytecode,
  args: ['MyToken', 18n, 1000000n],
})

console.log('Contract address:', result.address) // ct_...

Parameters

ParameterTypeDefaultDescription
aciAciRequired. Contract ACI.
bytecodestringRequired. Compiled bytecode.
argsunknown[][]Init function arguments.
amountbigint0nAE to send to the contract.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.

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.

Reading Contract State

Use readContract for stateless (dry-run) calls — no transaction, no fees:

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

const balance = await readContract(config, {
  address: 'ct_token...',
  aci: tokenAci,
  fn: 'balance',
  args: ['ak_owner...'],
})

Writing to a Contract

Use callContract for stateful calls that create on-chain transactions:

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

const result = await callContract(config, {
  address: 'ct_token...',
  aci: tokenAci,
  fn: 'transfer',
  args: ['ak_recipient...', 500n],
})

Parameters

ParameterTypeDefaultDescription
addressstringRequired. Contract address (ct_...).
aciAciRequired. Contract ACI.
fnstringRequired. Function name.
argsunknown[][]Function arguments.
amountbigint0nAE to attach (payable).
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.

Working with ACI

The ACI is generated by the Sophia compiler. You can obtain it via:

  1. CLI: reactive generate reads contract source and outputs typed ACI
  2. Compiler: Use the HTTP compiler API directly
  3. Manual: Include the JSON ACI in your project
typescript
import { tokenAci } from './generated/token'

const balance = await readContract(config, {
  address: 'ct_...',
  aci: tokenAci,
  fn: 'balance',
  args: ['ak_...'],
})

AEX-9 Tokens

AEX-9 is the Aeternity fungible token standard (equivalent to ERC-20). A typical AEX-9 contract exposes:

FunctionTypeDescription
meta_inforeadToken name, symbol, decimals
total_supplyreadTotal token supply
balancereadBalance of an account
allowancereadSpending allowance
transferwriteTransfer tokens
approvewriteApprove spending
transfer_allowancewriteTransfer on behalf of
typescript
const info = await readContract(config, {
  address: 'ct_token...',
  aci: aex9Aci,
  fn: 'meta_info',
  args: [],
})
// { name: 'MyToken', symbol: 'MTK', decimals: 18n }