EVM Chain
The EVM (Ethereum Virtual Machine) chain implementation in Signet.js provides support for all EVM-compatible networks, including Ethereum, Binance Smart Chain, Polygon, Arbitrum, and more.
Overview
The EVM implementation allows you to:
- Derive addresses and public keys
- Check balances
- Prepare, sign, and broadcast transactions
- Sign messages (EIP-191)
- Sign typed data (EIP-712)
Complete Transaction Example
Below is a complete example of sending a transaction on an EVM chain using Signet.js:
import { EVM } from 'signet.js'
import { utils } from 'signet.js'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { sepolia } from 'viem/chains'
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const publicClient = createPublicClient({
chain: sepolia,
transport: http(),
})
const walletClient = createWalletClient({
account,
chain: sepolia,
transport: http(),
})
const chainSigContract = new utils.chains.evm.ChainSignatureContract({
publicClient,
walletClient,
contractAddress: utils.constants.CONTRACT_ADDRESSES.ETHEREUM
.TESTNET_DEV as `0x${string}`,
})
const evm = new EVM({
rpcUrl: 'https://sepolia.infura.io/v3/YOUR-PROJECT-ID',
contract: chainSigContract,
})
const path = 'eth'
const predecessorId = walletClient.account.address
const { address: from, publicKey } = await evm.deriveAddressAndPublicKey(
predecessorId,
path
)
const { balance, decimals } = await evm.getBalance(from)
const { transaction, hashesToSign } = await evm.prepareTransactionForSigning({
from: from as `0x${string}`,
to: '0x4174678c78fEaFd778c1ff319D5D326701449b25',
value: 1n, // Amount in wei (1 wei in this example)
})
const rsvSignature = await chainSigContract.sign({
payload: hashesToSign[0],
path,
key_version: 0,
})
const tx = evm.finalizeTransactionSigning({
transaction,
rsvSignatures: [rsvSignature],
})
const txHash = await evm.broadcastTx(tx)
Supported Networks
You can use any EVM-compatible network by providing the appropriate RPC URL:
import { EVM } from 'signet.js'
// Ethereum Mainnet
const ethereumChain = new EVM({
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
contract: chainSigContract,
})
// Polygon (Matic)
const polygonChain = new EVM({
rpcUrl: 'https://polygon-rpc.com',
contract: chainSigContract,
})
// Binance Smart Chain
const bscChain = new EVM({
rpcUrl: 'https://bsc-dataseed.binance.org',
contract: chainSigContract,
})