Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Create and sign an ERC-20 token transfer.
import { DenClient } from "@onchainden/mls-sdk-ts"; import { privateKeyToAccount } from "viem/accounts"; import { encodeAbiParameters, encodeFunctionData, type Hex } from "viem"; const signer = privateKeyToAccount("0xYOUR_PRIVATE_KEY"); const client = new DenClient({ apiKey: process.env.DEN_API_KEY!, baseUrl: process.env.DEN_API_BASE_URL!, });
const erc20TransferAbi = [ { name: "transfer", type: "function", stateMutability: "nonpayable", inputs: [ { name: "to", type: "address" }, { name: "amount", type: "uint256" }, ], outputs: [{ name: "success", type: "bool" }], }, ]; const callData = encodeFunctionData({ abi: erc20TransferAbi, functionName: "transfer", args: ["0xRecipient...", 250_000_000n], });
const { data: queued } = await client.createTransaction({ accountId: "acc_123", initiatorWalletAddress: signer.address, networkId: 1, policyId: "pol_123", description: "USDC payout", to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", value: "0", data: callData, });
const initiatorSig = encodeAbiParameters( [ { type: "address", name: "address" }, { type: "bytes", name: "signature" }, ], [ signer.address, await signer.sign({ hash: queued.signatureData.initiatorPayload as Hex, }), ] ); const { data: afterInitiator } = await client.signTransaction(queued.id, { type: "initiator", signature: initiatorSig, }); if (afterInitiator.signatureData.status === "approvalReady") { await client.executeTransaction(queued.id, { type: "approve" }); }
import { DenClient } from "@onchainden/mls-sdk-ts"; import { privateKeyToAccount } from "viem/accounts"; import { encodeFunctionData } from "viem"; // 1) Set up the client and signer. const signer = privateKeyToAccount("0xYOUR_PRIVATE_KEY"); const client = new DenClient({ apiKey: process.env.DEN_API_KEY!, baseUrl: process.env.DEN_API_BASE_URL!, }); // 2) Build the transfer data. const erc20TransferAbi = [ { name: "transfer", type: "function", stateMutability: "nonpayable", inputs: [ { name: "to", type: "address" }, { name: "amount", type: "uint256" }, ], outputs: [{ name: "success", type: "bool" }], }, ]; const callData = encodeFunctionData({ abi: erc20TransferAbi, functionName: "transfer", args: ["0xRecipient...", 250_000_000n], }); // 3) Create the transaction. const { data: queued } = await client.createTransaction({ accountId: "acc_123", initiatorWalletAddress: signer.address, networkId: 1, policyId: "pol_123", description: "USDC payout", to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", value: "0", data: callData, }); // 4) Sign and execute. const initiatorSig = encodeAbiParameters( [ { type: "address", name: "address" }, { type: "bytes", name: "signature" }, ], [ signer.address, await signer.sign({ hash: queued.signatureData.initiatorPayload as Hex, }), ] ); const { data: afterInitiator } = await client.signTransaction(queued.id, { type: "initiator", signature: initiatorSig, }); if (afterInitiator.signatureData.status === "approvalReady") { await client.executeTransaction(queued.id, { type: "approve" }); }