Every Ethereum wallet works with OysBio Chain: browser extensions (MetaMask, Rabby, OKX, Coinbase Wallet), mobile wallets that accept a custom network, and hardware wallets through them. Your dApp talks to the wallet through the standard EIP-1193 provider.
Network values for manual setup#
| Field | OysBio Chain |
|---|---|
| Network name | OysBio Chain |
| RPC URL | https://rpc.oys.bio |
| Chain ID | 69797 |
| Currency symbol | OYS |
| Block explorer | https://explorer.oys.bio |
The Network parameters page and the explorer's home page have an Add to wallet button that does this in one click.
Browser dApp without libraries#
The complete example is wallet-dapp.html on the Downloads page: one HTML file, no build step, every call visible.
const CHAIN = {
chainId: '0x110a5', chainName: 'OysBio Chain',
nativeCurrency: { name: 'OYS', symbol: 'OYS', decimals: 18 },
rpcUrls: ['https://rpc.oys.bio'], blockExplorerUrls: ['https://explorer.oys.bio'], // https URLs only for MetaMask
};
const eth = window.ethereum;
// 1. switch to OysBio, adding it when the wallet does not know it (error 4902)
async function useOysBio() {
try {
await eth.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: CHAIN.chainId }] });
} catch (e) {
if (e.code !== 4902) throw e;
await eth.request({ method: 'wallet_addEthereumChain', params: [CHAIN] });
}
}
// 2. connect
const [account] = await eth.request({ method: 'eth_requestAccounts' });
// 3. send: the wallet signs and broadcasts
const hash = await eth.request({ method: 'eth_sendTransaction', params: [{ from: account, to, value: '0x' + (10n ** 16n).toString(16) }] });
// 4. wait until the transaction is final (Safe), not just included
async function waitForSafe(hash) {
for (;;) {
const r = await eth.request({ method: 'eth_getTransactionReceipt', params: [hash] });
const safe = await eth.request({ method: 'eth_getBlockByNumber', params: ['safe', false] });
if (r && r.status !== '0x1') throw new Error('reverted');
if (r && safe && BigInt(safe.number) >= BigInt(r.blockNumber)) return r;
await new Promise((ok) => setTimeout(ok, 1500));
}
}
Signing without sending (log-in, orders, approvals): personal_sign for text, eth_signTypedData_v4 for EIP-712 typed data with domain.chainId: 69797. The example page shows both.
Browser dApp with viem#
import { createWalletClient, createPublicClient, custom, http, parseEther } from 'viem';
import { oysbioTestnet, addOrSwitchChain, waitForSafe } from '@oysbio/sdk';
await addOrSwitchChain(window.ethereum, oysbioTestnet);
const wallet = createWalletClient({ chain: oysbioTestnet, transport: custom(window.ethereum) });
const client = createPublicClient({ chain: oysbioTestnet, transport: http() });
const [account] = await wallet.requestAddresses();
const hash = await wallet.sendTransaction({ account, to, value: parseEther('0.01') });
await waitForSafe(client, { hash });
With several wallets installed, listen for EIP-6963 eip6963:announceProvider events and let the user pick one; OysBio Explorer does this.
Backend or exchange (no browser)#
send-and-wait.mjs on the Downloads page: sign with a server key, send, and credit only when the block is safe.
import { createPublicClient, createWalletClient, http, parseEther } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { oysbioChain, waitForSafe } from '@oysbio/sdk';
const chain = oysbioChain('mainnet', { rpcUrl: process.env.OYSBIO_RPC_URL });
const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const wallet = createWalletClient({ chain, account, transport: http() });
const client = createPublicClient({ chain, transport: http() });
const hash = await wallet.sendTransaction({ to: process.argv[2], value: parseEther('0.01') });
const receipt = await waitForSafe(client, { hash });
console.log('final in block', receipt.blockNumber);
Deposits. Watch incoming transfers with eth_getLogs (tokens) or block scanning (native coin), and credit a deposit only once eth_getBlockByNumber("safe") has reached its block and the block hash is unchanged (isSafe in the SDK). The explorer API's /tx/{hash} returns finality.safe as well.
ethers v6#
import { BrowserProvider, JsonRpcProvider, parseEther } from 'ethers';
const provider = new BrowserProvider(window.ethereum, 69797);
const signer = await provider.getSigner();
const tx = await signer.sendTransaction({ to, value: parseEther('0.01') });
const read = new JsonRpcProvider('https://rpc.oys.bio', 69797);
const safe = await read.send('eth_getBlockByNumber', ['safe', false]);
Things to know#
- Public RPC never signs: use the wallet (
eth_sendTransactiongoes to the wallet, which signs and sends a raw transaction). - Fees are EIP-1559; wallets estimate them correctly. A priority fee of 1 wei or more is enough.
- Mobile wallets that cannot add networks from a dApp take the values in the table above.
- Tokens: ask the wallet to show a token with
wallet_watchAsset(watchTokenin the SDK). - Multisig treasuries: use the explorer's Multisig page; any owner wallet signs the approvals.