Create and sign an ERC-20 token transfer.
import { DenClient, NetworkId } from "@den/sdk";
import { privateKeyToAccount } from "viem/accounts";
import { encodeFunctionData } from "viem";
const signer = privateKeyToAccount("0xYOUR_PRIVATE_KEY");
const client = new DenClient({
apiKey: "ck_live_...",
rpcProviders: {
1: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
},
});
const erc20TransferAbi = [
{
name: "transfer",
type: "function",
stateMutability: "nonpayable",
inputs: [
{ name: "to", type: "address" },
{ name: "amount", type: "uint256" },
],
outputs: [{ name: "success", type: "bool" }],
},
];
const data = encodeFunctionData({
abi: erc20TransferAbi,
functionName: "transfer",
args: ["0xRecipient...", 250_000_000n],
});
const queued = await client.createTransaction("acc_123", {
networkId: NetworkId.ETHEREUM,
policyId: "pol_123",
description: "USDC payout",
to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
value: "0",
data,
});
const initiatorSig = await signer.signMessage({
message: queued.signingPayloads.initiatorPayload,
});
const afterInitiator = await client.signTransaction("acc_123", queued.id, {
type: "initiator",
signature: initiatorSig,
});
if (afterInitiator.signatureStatus === "approvalReady") {
await client.executeTransaction("acc_123", queued.id, { type: "approve" });
}
import { DenClient, NetworkId } from "@den/sdk";
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: "ck_live_...",
rpcProviders: {
1: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
},
});
// 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 data = encodeFunctionData({
abi: erc20TransferAbi,
functionName: "transfer",
args: ["0xRecipient...", 250_000_000n],
});
// 3) Create the transaction.
const queued = await client.createTransaction("acc_123", {
networkId: NetworkId.ETHEREUM,
policyId: "pol_123",
description: "USDC payout",
to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
value: "0",
data,
});
// 4) Sign and execute.
const initiatorSig = await signer.signMessage({
message: queued.signingPayloads.initiatorPayload,
});
const afterInitiator = await client.signTransaction("acc_123", queued.id, {
type: "initiator",
signature: initiatorSig,
});
if (afterInitiator.signatureStatus === "approvalReady") {
await client.executeTransaction("acc_123", queued.id, { type: "approve" });
}