@terminal3/t3n-client
v0.2.0
Published
T3n stateless client - contract invocation and discovery over an API key or bearer token, with no session and no runtime dependencies
Readme
T3n stateless client
@terminal3/t3n-client calls a T3n node in one request, with no handshake and no session. The agent authenticates with an API key or an OAuth bearer token, and the node verifies it. The package has no runtime dependencies.
@terminal3/t3n-sdk re-exports invoke and the discover* reads with their option and discovery result types, parseContractResponse, the z-space wire helpers, the token units, NODE_URLS, and most of the error classes (T3nError, RpcError and the session, handshake and WASM errors). SDK users need not install the client separately.
With both packages installed, they must resolve to one copy of the client or instanceof fails across them: install the client version the SDK depends on, and don't put a newer client beside the SDK or mix the public client with the internal SDK.
Installation
pnpm add @terminal3/t3n-clientUsage
import { invoke, discoverWhoami, NODE_URLS } from "@terminal3/t3n-client";
const baseUrl = NODE_URLS.testnet;
const accessToken = "<oauth-access-token>";
// API key: sent as `X-T3N-Api-Key`.
const me = await discoverWhoami({ baseUrl, apiKey: process.env.T3N_API_KEY! });
// OAuth bearer token: sent as `Authorization: Bearer`.
const result = await invoke({
baseUrl,
bearer: accessToken,
request: {
contract_id: "z:<org-tid>:<contract>",
contract_version: "1.0.0",
function_name: "<function>",
input: {},
},
});baseUrl must be https:; loopback hosts are exempt for local development. Transport failures throw InvokeError with a fixed message that never contains the credential or the response body.
Contents
invokeand thediscover*reads (whoami,contracts.list,delegation.check,describe.contract,describe.function).parseContractResponsefor decoding a contract result.requestToWirefor projecting plain arguments into a contract's wire body.formatTokens/toBaseUnitsfor token amounts.NODE_URLSand theEnvironmenttype.- The
T3nErrorfamily of error types.
