sage-soneium
v1.1.1
Published
TypeScript client for connecting to the Soneium blockchain
Readme
Soneium Blockchain Client
A TypeScript client for connecting to the Soneium blockchain, with support for Account Abstraction (ERC-4337).
Features
- Connect to Soneium mainnet and testnet (Minato)
- Send transactions
- Check balances and block numbers
- Account Abstraction support (ERC-4337)
- Sponsored (gasless) transactions
Setup
- Install dependencies:
npm install- Build the project:
npm run build- Configure environment variables in
.envfile (already set up for testnet)
Demo Scripts
1. Basic Testnet Connection
This script demonstrates a basic connection to the Soneium testnet, checking the current block number and an address balance:
node dist/testnet-demo.js2. Sending a Transaction
This script demonstrates sending a transaction on the Soneium testnet:
Edit
src/send-transaction-demo.tsand replace:YOUR_PRIVATE_KEYwith your private keyRECIPIENT_ADDRESSwith the recipient's address (optional)AMOUNT_TO_SENDwith the amount to send (optional)
Build and run:
npm run build
node dist/send-transaction-demo.js3. Account Abstraction (Gasless Transactions)
This script demonstrates using Account Abstraction to send a sponsored (gasless) transaction:
Edit
src/account-abstraction-demo.tsand replace:YOUR_PRIVATE_KEYwith your private keyYOUR_SCS_API_KEYwith your SCS API key (get one from Startale)RECIPIENT_ADDRESSwith the recipient's address (optional)AMOUNT_TO_SENDwith the amount to send (optional)
Build and run:
npm run build
node dist/account-abstraction-demo.jsGetting Testnet Tokens
To get testnet SON tokens, you can use the Soneium faucet:
- Visit the Soneium Faucet
- Enter your wallet address
- Complete the verification
- Receive testnet SON tokens
Soneium Testnet Information
- Network Name: Soneium Minato (Testnet)
- Chain ID: 999
- RPC URL: https://soneium-minato.rpc.scs.startale.com
- Explorer: https://explorer.minato.soneium.org
- Currency Symbol: SON
- Currency Decimals: 18
Using the Client in Your Code
import { SoneiumClient } from './dist';
// Create a client connected to the testnet
const client = new SoneiumClient('testnet');
// Connect a wallet (for sending transactions)
const address = client.connectWallet('0x...');
// Get the current block number
const blockNumber = await client.getBlockNumber();
console.log(`Current block number: ${blockNumber}`);
// Get the balance of an address
const balance = await client.getBalance('0x...');
console.log(`Balance: ${balance}`);
// Send a transaction
const txHash = await client.sendTransaction({
to: '0x...',
value: 1000000000000000000n, // 1 SON
});
console.log(`Transaction hash: ${txHash}`);Account Abstraction Example
import { sendSponsoredTransaction } from './dist';
// Send a sponsored transaction
const txHash = await sendSponsoredTransaction(
'0xYourPrivateKey',
'0xRecipient',
'0.01', // Amount in SON
'your-scs-api-key',
'testnet'
);
console.log(`Sponsored transaction hash: ${txHash}`);