.001 · SDK · TypeScript
Wire your agent to the chain.
Verax ships an Anchor-generated IDL. Use the standard @coral-xyz/anchor client. The full in-app implementation lives in lib/solventClient.ts — these snippets are the minimal subset to integrate from a fresh project.
01Install
bashnpm install @coral-xyz/anchor @solana/web3.js \
@solana/wallet-adapter-react @solana/wallet-adapter-react-ui02Build the program client
tsimport { AnchorProvider, Program } from "@coral-xyz/anchor";
import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js";
import idl from "./solvent-idl.json";
const PROGRAM_ID = new PublicKey(
"DgDSDfeQyZndeHAj5jdbfTyh7DpA6mh85BbV7DYi1HhC",
);
export function buildProgram(connection, wallet) {
const provider = new AnchorProvider(connection, wallet, {
commitment: "confirmed",
});
return new Program(idl, provider);
}03Derive PDAs
tsimport { PublicKey } from "@solana/web3.js";
const RESERVE_SEED = Buffer.from("reserve");
const LANE_SEED = Buffer.from("lane");
export function reservePda(authority) {
return PublicKey.findProgramAddressSync(
[RESERVE_SEED, authority.toBuffer()],
PROGRAM_ID,
);
}
export function lanePda(reserve, handle) {
return PublicKey.findProgramAddressSync(
[LANE_SEED, reserve.toBuffer(), Buffer.from(handle)],
PROGRAM_ID,
);
}04Create a reserve
tsawait program.methods
.createReserve("main")
.accountsStrict({
authority: wallet.publicKey,
reserve: reservePda(wallet.publicKey)[0],
systemProgram: SystemProgram.programId,
})
.rpc();05Open a lane
tsconst [reserve] = reservePda(wallet.publicKey);
const [lane] = lanePda(reserve, "@research");
await program.methods
.openLane("@research", new BN(0.1 * LAMPORTS_PER_SOL))
.accountsStrict({
authority: wallet.publicKey,
reserve,
lane,
systemProgram: SystemProgram.programId,
})
.rpc();06Attest (mutate trust)
ts// Mutate trust_bps by +200 (= +2%). Range clamped to [50, 9900] on chain.
await program.methods
.attest(200)
.accountsStrict({
authority: wallet.publicKey,
reserve,
lane,
})
.rpc();note · v0.1: only the reserve authority can attest. v0.2 will let any approved attestor sign.
07Settle outbound payment
ts// Sends from the reserve PDA via signed CPI.
// Reverts if amount would exceed effective_cap = base × mult(trust).
await program.methods
.settle(new BN(0.005 * LAMPORTS_PER_SOL))
.accountsStrict({
authority: wallet.publicKey,
reserve,
lane,
recipient: recipientPubkey,
systemProgram: SystemProgram.programId,
})
.rpc();08Fetch state
ts// Single reserve
const reserve = await program.account.reserve.fetch(reservePda(authority)[0]);
// All lanes owned by a reserve
const lanes = await program.account.lane.all([
{ memcmp: { offset: 8, bytes: reservePda(authority)[0].toBase58() } },
]);