Skip to content

spend

Sends AE tokens to a recipient address.

Import

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

Usage

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

const result = await spend(config, {
  recipient: 'ak_2dATGVvfU1oBShDDsaqfh1sF4bCkx2FKbiCaL2t4zZpMMpMfgE',
  amount: '1.5', // in AE
})

Return Type

typescript
type SpendReturnType = {
  hash: string
  rawTx: string
}

Parameters

ParameterTypeDefaultDescription
recipientstringRequired. Recipient address (ak_... or AENS name).
amountbigint | stringRequired. Amount to send. Strings are parsed as AE, bigints as aettos.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.
noncenumberautoAccount nonce. Auto-fetched if omitted.
feebigintautoTransaction fee in aettos. Auto-calculated if omitted.
payloadstring''Optional payload data attached to the transaction.

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

Send with custom TTL

typescript
const result = await spend(config, {
  recipient: 'ak_2dA...',
  amount: '10',
  ttl: 50, // 50 blocks (~2.5 hours)
})

Send exact aettos

typescript
const result = await spend(config, {
  recipient: 'ak_2dA...',
  amount: 1000000000000000000n, // 1 AE in aettos
})

Send to AENS name

typescript
const result = await spend(config, {
  recipient: 'alice.chain',
  amount: '5',
})

Error Types

typescript
import type { SpendErrorType } from '@growae/reactive'
  • ConnectorNotConnectedError — no wallet connected
  • InsufficientBalanceError — not enough AE
  • NodeRequestError — the node returned an error