TypeScript integration
Environment and dependencies
Use an environment supporting ES modules, bigint and top-level await. Install compatible @invisi-labs/sdk, @invisi-labs/prover and ethers packages, adding @invisi-labs/session for managed inventory. Match the package version to these APIs using the compatibility guide.
The examples below are a complete offline script and host-callable functions. Functions require real test-environment services, assets and wallet capabilities; never fund the illustrative addresses.
Construct a Note output offline
This script creates an output intent without service access or fund movement. The receiving material is a public example; the 0x111… and 0x222… addresses only bind the offline example. 10n means ten base units. Save it as .ts and execute with your project’s configured TypeScript runner.
import { NoteOutput } from "@invisi-labs/sdk";
const output = await NoteOutput.create({
chainId: 31337n,
protocolAddress: "0x1111111111111111111111111111111111111111",
tokenAddress: "0x2222222222222222222222222222222222222222",
amount: 10n,
recipient: { type: "invisi", address: "0i0e0525SFRf53yh2aljmm3sn9JQ5nJk7LqWt0G2ajnRY2pe698y550QXhp9uELXpcCZMf5Y608rRDJ68jJgfEWy5j7U5e5eVNPVz8vW2W2kmyw4p9lVLwW3z3WeFHQs5KdfR980CX" },
});
console.log(output.commitment);
Fresh randomization changes the commitment each time. A commitment is not evidence that a funded on-chain Note exists or a payment succeeded.
Connect a protocol environment
chainRpcUrl is a general chain node. protocolRpcUrl is the Protocol RPC /v1 entry. Supply chainId and coreAddress from trusted deployment configuration, rather than copying an untrusted response. bbBin and coreCatalog select a matching local BB executable and authenticated Core resource directory.
import { JsonRpcProvider } from "ethers";
import { Invisi, Protocol, ProtocolRpcClient } from "@invisi-labs/sdk";
import { NativeProver } from "@invisi-labs/prover/native";
export async function connectProtocol(options: {
chainRpcUrl: string; protocolRpcUrl: string;
chainId: bigint; coreAddress: string;
bbBin: string; coreCatalog: string;
}) {
const provider = new JsonRpcProvider(options.chainRpcUrl);
try {
const protocolRpc = new ProtocolRpcClient(options.protocolRpcUrl);
const protocol = await Protocol.fromRpc(protocolRpc, provider);
if (protocol.context.chainId !== options.chainId ||
protocol.context.protocolAddress.toLowerCase() !== options.coreAddress.toLowerCase()) {
throw new Error("Unexpected network or Core instance");
}
const prover = new NativeProver({
bbBin: options.bbBin,
resources: { directory: options.coreCatalog, offline: true },
});
const invisi = new Invisi({ provider, protocolRpc, prover });
return { provider, protocolRpc, protocol, invisi };
} catch (error) {
provider.destroy();
throw error;
}
}
After a successful connection, the caller owns provider.destroy() at shutdown. Stop on resource authentication failure; do not silently choose another mirror or proof version.
Prepare your first public deposit
This exported function takes connected invisi and protocol, a complete public payer Wallet, token address, full 0i recipient address and base-unit amount. It only returns an unsigned transaction; it does not approve, sign or send.
import { Invisi, NoteOutput, Protocol, Wallet } from "@invisi-labs/sdk";
export async function prepareDeposit(
invisi: Invisi, protocol: Protocol, payer: Wallet,
tokenAddress: `0x${string}`, recipientAddress: `0i${string}`, amount: bigint,
) {
if (amount <= 0n) throw new Error("Amount must be positive base units");
const output = await NoteOutput.create({
...protocol.context, tokenAddress, amount,
recipient: { type: "invisi", address: recipientAddress },
});
const prepared = await invisi.prepareShield({
wallet: payer, protocol, tokenAddress, outputs: [output],
funding: { payer: payer.ownerAddress, amount, authorization: "caller" },
});
const ready = await prepared.ready();
return ready.exportTransaction();
}
Public funding uses ready(), without ZK prove(). The EVM submitter must satisfy caller funding’s payer requirement and have ERC-20 balance, allowance to Core and gas. Review the target, amount and calldata before host submission.
Verify events and confirmation after submission. On a timeout, retain the original operation and hash rather than creating another output.
Next: synchronize and pay with WalletSession.
Download the complete offline example