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)| Field | Required | Description |
|---|---|---|
| to | Yes | `string` — recipient `0x…` |
| amount | Yes | `string` — token base units |
Response: string calldata "0xa9059cbb…"
encodeErc20Approve
js
encodeErc20Approve(spender, amount)| Field | Required | Description |
|---|---|---|
| spender | Yes | `string` |
| amount | Yes | `string` — allowance base units |
Response: string calldata "0x095ea7b3…"
encodeErc721Transfer
js
encodeErc721Transfer(from, to, tokenId)| Field | Required | Description |
|---|---|---|
| from | Yes | `string` |
| to | Yes | `string` |
| tokenId | Yes | `string` |
Response: string calldata "0x23b872dd…"
buildErc20ApproveIntent
js
buildErc20ApproveIntent({ chainId, from, token, spender, amount })| Field | Required | Description |
|---|---|---|
| chainId | Yes | `GrayChainId` |
| from | Yes | `string` — owner |
| token | Yes | `string` — ERC-20 contract |
| spender | Yes | `string` — router / vault |
| amount | Yes | `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
| Field | Required | Description |
|---|---|---|
| invalid_argument | No | Non-hex addresses or non-numeric amount strings where parsing fails. |