@altananetwork/sdk
v0.9.0
Published
TypeScript SDK for creating non-custodial smart agentic wallets with on-chain session-key delegation.
Maintainers
Readme
@altananetwork/sdk
TypeScript SDK for creating non-custodial smart agentic wallets with on-chain session-key delegation.
npm install @altananetwork/sdk viemQuick start
Create a client for the chains you want. Pass one L1 or several: the same wallet address works on every chain you configure.
import { createClient, ETHEREUM, BNB } from "@altananetwork/sdk";
// Both L1s, or just one, your choice.
const client = createClient({ chains: [ETHEREUM, BNB] });Passkey wallet (browser)
const wallet = await client.createPasskeyWallet({ name: "My Agent Wallet" });Private-key wallet (server / agent)
import { signerFromPrivateKey } from "@altananetwork/sdk";
const signer = signerFromPrivateKey(process.env.PRIVATE_KEY);
const wallet = await client.createWallet({ signer });Grant a session and execute
Operations take an optional chainId (defaults to the client's first chain):
const session = await client.grantSession({
wallet,
signer,
permissions: {
calls: [{ to: "0x…" }],
spend: [{ limit: 1_000_000n, period: "day" }], // 1 USDC/day
},
expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour
});
await client.execute({
session,
chainId: 56, // BNB Smart Chain; omit to use the default chain
calls: [{ to: "0x…", value: 0n, data: "0x…" }],
});Pay for an API with x402
A session key can pay for HTTP resources via the x402 standard (Permit2 or EIP-3009 rails), settled on-chain from the smart wallet. Provision once, then pay transparently:
import { PERMIT2_ADDRESS } from "@altananetwork/sdk";
// One-time, as admin (permit2 rail):
await client.approveTokenForPermit2({ wallet, signer, token: "0xUSDC…" });
await client.approveSignatureChecker({ wallet, signer, session, checker: PERMIT2_ADDRESS });
// The agent pays + fetches (server-side):
const res = await client.fetchWithX402({ session, url: "https://api.example.com/paid" });Payments are authorized with the account's ERC-1271 signature. See Off-chain signatures.
Hire another agent (ERC-8183)
Agents can hire and pay each other for work. hireErc8183Agent runs the whole
buyer flow (create, register, budget, approve, fund) as one atomic relay
intent, and returns once the job is funded on-chain.
import { hireErc8183Agent, getErc8183Job, BNB } from "@altananetwork/sdk";
const { jobId } = await hireErc8183Agent(session, {
provider: "0xSellerAgentAddress",
task: "Audit wallet 0x…'s Venus position and recommend an action.",
budget: 100_000_000_000_000_000n, // 0.1 $U (18 decimals)
}, { network: BNB });
const job = await getErc8183Job(BNB, jobId); // OPEN, FUNDED, SUBMITTED, COMPLETEDThe admin path is hireErc8183Agent(wallet, signer, params, opts). Using the
session path instead means a scoped key with an on-chain spend limit caps what
an autonomous agent can ever escrow. settleErc8183Job approves or disputes on
delivery, and buildClaimRefundCall recovers the budget if nothing arrives.
Full reference: ERC-8183 agent jobs.
Give an agent an identity (ERC-8004)
Buyers find sellers through the ERC-8004 identity registry. An agent can mint
and maintain its own entry with a session key scoped to just those two calls —
erc8004RegisterPermissions grants register and setAgentURI on the
registry and nothing else, so a compromised session cannot transfer the
identity away or approve an operator that outlives its revocation.
import {
erc8004RegisterPermissions,
registerErc8004Agent,
setErc8004AgentUri,
encodeErc8004AgentUri,
withErc8004Registration,
BNB,
} from "@altananetwork/sdk";
// Grant: permissions: { calls: erc8004RegisterPermissions(56), spend: [...] }
const record = {
type: "https://eips.ethereum.org/EIPS/eip-8004#registration-v1",
name: "Vault Sentinel",
description: "Watches Venus positions.",
services: [{ name: "A2A", endpoint: "https://sentinel.example/.well-known/agent-card.json" }],
registrations: [], // the id does not exist until the mint assigns it
} as const;
const { agentId } = await registerErc8004Agent(
session,
{ agentUri: encodeErc8004AgentUri(record) },
{ network: BNB },
);
await setErc8004AgentUri(
session,
{ agentId, agentUri: encodeErc8004AgentUri(withErc8004Registration(record, agentId, 56)) },
{ network: BNB },
);Registration is two-phase because the record embeds the id the mint assigns.
getErc8004Agent(BNB, agentId) reads the owner and record back — persist the
agentId, as the registry has no reverse lookup.
Full reference: ERC-8004 agent identity.
Documentation
Full docs, concept guides, and SDK reference: docs.altana.network.
Source: github.com/altananetwork/altana-sdk.
License
Apache-2.0
