Skip to content

radius-workshop/radius-wallet-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

radius-wallet-ts

A simple TypeScript library for interacting with the Radius network. Built on viem.

Check balances, send tokens, request faucet funds, deploy contracts, and interact with smart contracts.

Quick Start

npm install viem

# Generate a new key
node -e "import('viem/accounts').then(m => console.log(m.generatePrivateKey()))"

# Set your private key
export RADIUS_PRIVATE_KEY=0x...
import { RadiusWallet } from "./src/index.js";

const wallet = RadiusWallet.fromEnv();
console.log(await wallet.getBalances());

API

Create / Load Wallet

// From private key
const wallet = new RadiusWallet("0xYOUR_PRIVATE_KEY");

// Generate new wallet
const wallet = RadiusWallet.create();
console.log(wallet.address);

// From environment variable (RADIUS_PRIVATE_KEY)
const wallet = RadiusWallet.fromEnv();

// Use mainnet
const wallet = new RadiusWallet("0x...", { chain: "mainnet" });

Check Balances

await wallet.getRusdBalance();               // Your RUSD balance
await wallet.getSbcBalance();                 // Your SBC balance
await wallet.getBalances();                   // Both as { address, rusd, sbc }

await wallet.getSbcBalance("0x1234...");      // Someone else's balance

Send Tokens

// Send SBC (amounts are strings, decimals handled automatically)
const hash = await wallet.sendSbc("0xRecipient", "1.5");

// Send RUSD (native token)
const hash = await wallet.sendRusd("0xRecipient", "0.001");

// Wait for confirmation
const receipt = await wallet.waitForTx(hash);
console.log(receipt.status);  // "success" or "reverted"
console.log(wallet.explorerUrl(hash));

Transaction Status

const receipt = await wallet.getTxReceipt(hash);
const receipt = await wallet.waitForTx(hash);  // Waits for confirmation
wallet.explorerUrl(hash);                       // Link to block explorer

Faucet (Testnet)

const result = await wallet.requestFaucet();  // Requests SBC from testnet faucet

requestFaucet() is testnet-only and throws when the wallet is configured for mainnet.

Deploy Contracts

import MyContract from "./artifacts/MyContract.json";

const result = await wallet.deployContract(
  MyContract.abi,
  MyContract.bytecode as `0x${string}`,
  [constructorArg1, constructorArg2]  // optional
);
console.log(result.address);
console.log(result.txHash);

Read from Contracts

const count = await wallet.readContract(
  "0xContractAddress",
  counterAbi,
  "getCount"
);

Write to Contracts

const hash = await wallet.writeContract(
  "0xContractAddress",
  erc20Abi,
  "transfer",
  ["0xRecipient", 1000000n]
);
const receipt = await wallet.waitForTx(hash);

Radius Network Details

Testnet Mainnet
RPC https://rpc.testnet.radiustech.xyz https://rpc.radiustech.xyz
Chain ID 72344 723487
Explorer https://testnet.radiustech.xyz https://network.radiustech.xyz

Tokens:

  • RUSD — Native token, 18 decimals (used for gas)
  • SBC — ERC-20 stablecoin, 6 decimals, at 0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb

Things to know:

  • Gas price is fixed (~1 gwei). No EIP-1559, no priority fees.
  • Block numbers are timestamps in milliseconds (not sequential).
  • Sub-second finality — no reorgs possible.
  • Failed transactions don't charge gas.

Exported Constants

import {
  radiusTestnet,    // viem Chain definition
  radiusMainnet,    // viem Chain definition
  SBC_ADDRESS,      // SBC token contract address
  SBC_DECIMALS,     // 6
  RUSD_DECIMALS,    // 18
  ERC20_ABI,        // Minimal ERC-20 ABI
} from "./src/index.js";

Examples

See the examples/ directory:

  • check-balance.ts — Query balances
  • send-sbc.ts — Send an SBC transfer
  • request-faucet.ts — Get testnet tokens

Run with: npx tsx examples/check-balance.ts

Production Notes

This library uses a local private key for signing. For production, use a managed signing service like Privy. See the Nanda Wallet Concierge for an example.

About

Simple TypeScript wallet library for the Radius network

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors