Docs
Build

SDK

@oysbio/sdk on npm: chain definitions for viem, an explorer client, Safe finality, wallet helpers and a verification CLI.

A small JavaScript library on top of viem: OysBio chain definitions, a typed client for the explorer API, helpers for Safe finality, wallets, the faucet and contract verification, and the logic behind the explorer's Multi-Send and multisig pages. It runs in browsers and Node 20+.

Install#

npm install @oysbio/sdk viem

The package is on npm; viem 2.57 or newer is a peer dependency.

Chains#

import { oysbio, oysbioTestnet, oysbioChain } from '@oysbio/sdk';
import { createPublicClient, http } from 'viem';

const client = createPublicClient({ chain: oysbioTestnet, transport: http() });   // public endpoints
const local = oysbioChain('mainnet', { rpcUrl: 'https://rpc.oys.bio' });                 // your own node or endpoint

oysbio (69797) and oysbioTestnet (69798) carry the public RPC endpoint, the WebSocket URL and the explorer with its API URL. EVM_VERSION is "paris" (the default target of the templates); EVM_VERSIONS lists the targets that run (paris, shanghai, cancun, see Deploying contracts). BLOCK_TIME_SECONDS is 3.

Finality#

import { waitForSafe, getSafeBlock, isSafe } from '@oysbio/sdk';

const hash = await wallet.sendTransaction({ to, value });
const receipt = await waitForSafe(client, { hash, onStatus: (s) => console.log(s) });  // 'included', then 'safe'
const safe = await getSafeBlock(client);                                               // { number, hash, timestamp }

waitForSafe throws if the transaction reverted, left the canonical chain, or was not Safe in time (default 180 s). A block is usually Safe a few seconds after it is sealed.

Explorer API#

import { createExplorerClient } from '@oysbio/sdk';

const explorer = createExplorerClient({ chain: oysbioTestnet });   // or { apiUrl: 'https://explorer.oys.bio/api' }
const tx = await explorer.tx(hash);              // tx.finality.safe
const acct = await explorer.address('0x…', { tab: 'transfers' });
const holders = await explorer.token(tokenAddress, { tab: 'holders' });
await explorer.requestFaucet('0xYourAddress');   // testnet
const pools = await explorer.swap();             // OysBio DeFi pools and tokens
const es = new EventSource(explorer.liveUrl);    // new blocks (Server-Sent Events)

Every endpoint of the API has a method (validatorPerformance, swapTrades, marketHeld, bridgeMessage, intentsQuote, miningSubmit, privacyRelay and so on); explorer.request(path, { query }) reaches any other. Errors throw ExplorerError with status and the server's message. Pass apiKey (or set OYSBIO_API_KEY) for the higher rate limit.

Wallets#

import { addOrSwitchChain, watchToken, oysbioTestnet } from '@oysbio/sdk';

await addOrSwitchChain(window.ethereum, oysbioTestnet);   // 'switched' or 'added'
await watchToken(window.ethereum, { address, symbol: 'tUSD', decimals: 6 });

addOrSwitchChain adds the network when the wallet does not know it, and connects first when the wallet lets only connected sites change the network (code 4100, as OysBio Wallet does). See Wallet integration for complete examples.

Contract verification (Node)#

import { createExplorerClient, verifyContract } from '@oysbio/sdk/node';
import { privateKeyToAccount } from 'viem/accounts';

await verifyContract({
  explorer: createExplorerClient({ chain: oysbioTestnet }),
  account: privateKeyToAccount(process.env.PRIVATE_KEY),   // only signs in; sends nothing
  address: '0x…', contract: 'src/MyToken.sol:MyToken', buildInfoDir: 'out/build-info',
});

It reads Foundry build info (build_info = true in foundry.toml, as in the template) and Hardhat build info. A contract that is already verified with an exact match counts as done; a partial match stays an error.

Command line#

oysbio chain     --network testnet                       # chain ID, endpoints, wallet_addEthereumChain parameters
oysbio faucet    0xYourAddress                           # testnet coins
oysbio safe-block --network testnet                      # newest final block
oysbio wait-safe 0xTxHash                                # waits until the transaction is final
oysbio verify    0xContract src/MyToken.sol:MyToken --build-info out/build-info
oysbio version

Run it with npx oysbio … in a project that has the package, or install it globally (npm install -g @oysbio/sdk viem).

Options: --network mainnet|testnet (default testnet), --rpc <url>, --explorer <explorer root>; or OYSBIO_NETWORK, OYSBIO_RPC_URL, OYSBIO_EXPLORER_URL. verify reads the key from OYSBIO_PRIVATE_KEY or PRIVATE_KEY.

Multi-Send, multisig and governance#

import { planBatches, callFor, checkReceipt } from '@oysbio/sdk/multisend';
import { createSafeCall, safeTxTypedData, packSignatures, execCall, templates } from '@oysbio/sdk/multisig';
import { scheduleTx, executeTx, operationId, actions } from '@oysbio/sdk/governance';

The same code the explorer's Multi-Send, Multisig and Governance pages use: batching transfers by real gas, creating Safes at a predictable address, building the EIP-712 SafeTx for owners to sign, the execTransaction call, and timelock operations. Each sub-path has TypeScript declarations.