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) Encode the vault deposit.
const erc4626DepositAbi = [
{
name: "deposit",
type: "function",
stateMutability: "nonpayable",
inputs: [
{ name: "assets", type: "uint256" },
{ name: "receiver", type: "address" },
],
outputs: [{ name: "shares", type: "uint256" }],
},
];
const data = encodeFunctionData({
abi: erc4626DepositAbi,
functionName: "deposit",
args: [1_000_000_000n, "0xReceiver..."],
});
// 3) Create the deposit transaction.
const queued = await client.createTransaction("acc_123", {
networkId: NetworkId.ETHEREUM,
policyId: "pol_123",
description: "Deposit into vault",
to: "0xVaultAddress...",
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" });
}