Skip to content
Docs

Client: signing

Encoding helpers

ERC-20 / ERC-721 calldata helpers and approve contract_call intents.

Overview

Pure calldata helpers for EVM contract interactions. Pair with signEvmTransaction or a Cloud contract_call prepare.

encodeErc20Transfer

js
encodeErc20Transfer(to, amount)
FieldRequiredDescription
toYes`string` — recipient `0x…`
amountYes`string` — token base units

Response: string calldata "0xa9059cbb…"

encodeErc20Approve

js
encodeErc20Approve(spender, amount)
FieldRequiredDescription
spenderYes`string`
amountYes`string` — allowance base units

Response: string calldata "0x095ea7b3…"

encodeErc721Transfer

js
encodeErc721Transfer(from, to, tokenId)
FieldRequiredDescription
fromYes`string`
toYes`string`
tokenIdYes`string`

Response: string calldata "0x23b872dd…"

buildErc20ApproveIntent

js
buildErc20ApproveIntent({ chainId, from, token, spender, amount })
FieldRequiredDescription
chainIdYes`GrayChainId`
fromYes`string` — owner
tokenYes`string` — ERC-20 contract
spenderYes`string` — router / vault
amountYes`string` — allowance (base units)
ts
type ContractCallIntent = {
  kind: "contract_call";
  chainId: GrayChainId;
  from: string;
  to: string;       // token contract
  data: string;     // approve calldata
  value: "0";
};

Usage

js
import {
  encodeErc20Transfer,
  encodeErc20Approve,
  encodeErc721Transfer,
  buildErc20ApproveIntent,
} from "@gray3/client";

const data = encodeErc20Transfer(recipient, "1000000");
const intent = buildErc20ApproveIntent({
  chainId: "ethereum",
  from: a.address("evm"),
  token: usdc,
  spender: router,
  amount: "115792089237316195423570985008687907853269984665640564039457584007913129639935",
});
const prepared = await gray.transactions.prepare(intent);

Throws

FieldRequiredDescription
invalid_argumentNoNon-hex addresses or non-numeric amount strings where parsing fails.