Integrate Embedded Wallets with the Soneium Blockchain in Node
While using the Web3Auth Node SDK, you get a Ethers Signer on successful authentication. This signer can be used with libraries like ethers.js etc. to make Soneium blockchain calls like getting the user's account, fetching balance, sign transaction, send transaction, read from and write to the smart contract, etc. We have highlighted a few here to get you started quickly on that.
Chain Details for Soneium
- Mainnet
- Minato Testnet
- Chain ID: 0x74c
- Public RPC URL: https://mainnet-rpc.soneium.org
- Display Name: Soneium Mainnet
- Block Explorer Link: https://mainnet-explorer.soneium.org
- Ticker: ETH
- Ticker Name: Ethereum
- Chain ID: 0x79a
- Public RPC URL: https://testnet-rpc.soneium.org
- Display Name: Soneium Minato Testnet
- Block Explorer Link: https://testnet-explorer.soneium.org
- Ticker: ETH
- Ticker Name: Ethereum
Installation
To interact with the blockchain, you can use either the viem or
ethers.js library with Web3Auth.
- ethers.js
- viem
- npm
- Yarn
- pnpm
- Bun
npm install --save ethers
yarn add ethers
pnpm add ethers
bun add ethers
- npm
- Yarn
- pnpm
- Bun
npm install --save viem
yarn add viem
pnpm add viem
bun add viem
Initialize
const { Web3Auth } = require('@web3auth/node-sdk')
const web3auth = new Web3Auth({
clientId: 'YOUR_CLIENT_ID',
web3AuthNetwork: 'sapphire_mainnet', // or 'sapphire_devnet'
})
await web3auth.init()
const result = await web3auth.connect({
authConnectionId: 'YOUR_AUTH_CONNECTION_ID', // Your custom authentication connection name
idToken: 'USER_ID_TOKEN', // JWT token from your auth system
})
Get Account
// Get user's Ethereum public address
const address = result.signer.getAddress()
console.log('\x1b[33m%s\x1b[0m', 'Accounts:', address)
Get Balance
const address = await result.signer.getAddress()
const balance = ethers.formatEther(
await result.signer.provider.getBalance(address) // Balance is in wei
)
console.log('\x1b[33m%s\x1b[0m', 'Balance:', balance, 'ETH')
Sign a message
const signature = await result.signer.signMessage(message)
console.log('\x1b[33m%s\x1b[0m', 'Signed Message:', signature)