Skip to main content

Integrate Embedded Wallets with the Arbitrum 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 Arbitrum 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 Arbitrum

  • Chain ID: 0xa4b1
  • RPC URL: You can use our bundled RPC service from Infura, or your own choice of RPC service for production.
  • Display Name: Arbitrum One
  • Block Explorer Link: https://arbiscan.io
  • Ticker: ETH
  • Ticker Name: Ethereum

Installation

To interact with the blockchain, you can use either the viem or ethers.js library with Web3Auth.

npm install --save ethers

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)