Build with Functor
Give an agent a wallet and a policy
createWallet, grantSession, execute, and revokeSession.You own the wallet. The agent gets a scoped key: it can only call the contracts you allow, only up to the spend cap you set, and it expires automatically. You can cut access with one transaction at any time.
Step 1: Create your wallet
This is your wallet. You're the admin. The agent never sees this key.
import { createClient, BNB_TESTNET, signerFromPrivateKey } from "@functornetwork/agentic-wallet";
const client = createClient({ chains: [BNB_TESTNET] });
const signer = signerFromPrivateKey(process.env.PRIVATE_KEY as `0x${string}`);
const wallet = await client.createWallet({ signer });
console.log(wallet.address);Fund wallet.address with testnet BNB before step 2: testnet.bnbchain.org/faucet-smart
Step 2: Grant the agent a session
This is the policy. You define which contracts the agent can call, the daily spend cap, and when the key expires. grantSession writes that policy onchain and returns a session object to hand to your agent.
import { createPrivateKeySigner } from "@functornetwork/agentic-wallet";
import { parseEther } from "viem";
const session = await client.grantSession({
wallet,
signer,
sessionSigner: createPrivateKeySigner(), // the agent's key — SDK generates it
permissions: {
calls: [{ to: "0xYourContract" }], // only this contract
spend: [{ limit: parseEther("0.1"), period: "day" }], // 0.1 BNB per day
},
expiry: Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60, // 7 days
});Replace 0xYourContract with your contract address.
To test on BNB testnet, try WBNB: 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd · Use Case 2 for DEX trading.
Pass session to your agent process. It holds the session key; treat it like a private key.
Step 3: The agent executes
The agent uses session to act. Your admin key is not involved.
const result = await client.execute({
session,
calls: [{ to: "0xYourContract", data: "0x", value: 0n }],
});
console.log(result.status, result.transactionHash);A call within the policy goes through. An oversized amount or a call to a different contract reverts at the onchain validator, not at Functor's backend, at the contract itself.
Step 4: Revoke the session
One call cuts the agent's access. Its next execute reverts immediately.
await client.revokeSession({ wallet, signer, session });Why it's different
The policy is onchain. Any tool, block explorer, or smart contract can verify whether the session key is still active by reading the keystore directly. Nothing to trust on Functor's side.
- Use Case 1b: the human side: a passkey wallet that delegates to an agent.
- Use Case 2: point this session at a real DEX.