EVM Chain Support
Overview
Aria Wallet provides full support for Ethereum and EVM-compatible chains through the standard Ethereum provider interface. This allows you to use familiar libraries like ethers.js and web3.js with Aria.
The wallet injects window.ethereum following the EIP-1193 standard, making it compatible with any dApp that supports MetaMask or other Ethereum wallets.
Supported Chains
Aria supports all major EVM chains out of the box:
Mainnets
- Ethereum (Chain ID: 1)
- Polygon (Chain ID: 137)
- Arbitrum One (Chain ID: 42161)
- Optimism (Chain ID: 10)
- Avalanche C-Chain (Chain ID: 43114)
- BNB Smart Chain (Chain ID: 56)
Testnets
- Sepolia (Chain ID: 11155111)
- Goerli (Chain ID: 5)
- Mumbai (Chain ID: 80001)
- Arbitrum Goerli (Chain ID: 421613)
Additional EVM chains can be added using the wallet_addEthereumChain method.
Connecting
Connect to Aria using the standard Ethereum provider methods:
// Check if Aria's EVM provider is available
if (!window.ethereum) {
alert("Please install Aria Wallet");
return;
}
// Request account access
const accounts = await window.ethereum.request({
method: "eth_requestAccounts"
});
const userAddress = accounts[0];
console.log("Connected:", userAddress);Using ethers.js
For a better developer experience, use ethers.js with Aria:
import { ethers } from "ethers";
async function connectWithEthers() {
// Check for Aria's EVM provider
if (!window.ethereum) {
throw new Error("Please install Aria Wallet");
}
// Create a Web3Provider using Aria
const provider = new ethers.BrowserProvider(window.ethereum);
// Request account access
await provider.send("eth_requestAccounts", []);
// Get the signer
const signer = await provider.getSigner();
const address = await signer.getAddress();
console.log("Connected:", address);
return { provider, signer, address };
}Ethereum Provider
Aria's Ethereum provider supports standard EIP-1193 methods:
| Method | Description |
|---|---|
eth_requestAccounts | Request wallet connection |
eth_accounts | Get connected accounts |
eth_chainId | Get current chain ID |
eth_sendTransaction | Send a transaction |
eth_sign | Sign a message |
personal_sign | Sign a personal message |
eth_signTypedData_v4 | Sign EIP-712 typed data |
wallet_switchEthereumChain | Switch to a different chain |
wallet_addEthereumChain | Add a custom chain |
Transactions
Send ETH and interact with smart contracts using ethers.js:
Send ETH
import { ethers } from "ethers";
async function sendEth() {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// Send 0.1 ETH
const tx = await signer.sendTransaction({
to: "0xRecipientAddress...",
value: ethers.parseEther("0.1"),
});
console.log("Transaction hash:", tx.hash);
// Wait for confirmation
const receipt = await tx.wait();
console.log("Confirmed in block:", receipt.blockNumber);
return receipt;
}Interact with Contracts
import { ethers } from "ethers";
// ERC-20 ABI (minimal)
const ERC20_ABI = [
"function balanceOf(address) view returns (uint256)",
"function transfer(address to, uint256 amount) returns (bool)",
"function symbol() view returns (string)",
"function decimals() view returns (uint8)"
];
async function interactWithToken() {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// Connect to a token contract
const tokenAddress = "0xTokenAddress...";
const contract = new ethers.Contract(tokenAddress, ERC20_ABI, signer);
// Read token info
const symbol = await contract.symbol();
const decimals = await contract.decimals();
const balance = await contract.balanceOf(await signer.getAddress());
console.log(`Balance: ${ethers.formatUnits(balance, decimals)} ${symbol}`);
// Transfer tokens
const tx = await contract.transfer(
"0xRecipient...",
ethers.parseUnits("10", decimals)
);
await tx.wait();
return tx;
}Message Signing
Sign messages for authentication or other off-chain purposes:
import { ethers } from "ethers";
async function signMessage() {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// Sign a simple message
const message = "Hello from Aria Wallet!";
const signature = await signer.signMessage(message);
console.log("Signature:", signature);
// Verify the signature
const recoveredAddress = ethers.verifyMessage(message, signature);
console.log("Recovered address:", recoveredAddress);
return signature;
}
async function signTypedData() {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
// EIP-712 typed data
const domain = {
name: "My dApp",
version: "1",
chainId: 1,
verifyingContract: "0x..."
};
const types = {
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" }
]
};
const value = {
name: "Alice",
wallet: "0x..."
};
const signature = await signer.signTypedData(domain, types, value);
return signature;
}Adding Networks
Add custom EVM networks or switch between chains:
async function addNetwork() {
try {
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [{
chainId: "0x89", // 137 in hex (Polygon)
chainName: "Polygon Mainnet",
nativeCurrency: {
name: "MATIC",
symbol: "MATIC",
decimals: 18
},
rpcUrls: ["https://polygon-rpc.com"],
blockExplorerUrls: ["https://polygonscan.com"]
}]
});
console.log("Network added successfully");
} catch (error) {
console.error("Failed to add network:", error);
}
}
async function switchNetwork() {
try {
await window.ethereum.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: "0x1" }] // Ethereum Mainnet
});
} catch (error) {
// If the chain hasn't been added, add it
if (error.code === 4902) {
await addNetwork();
}
}
}Event Listeners
Listen for account and chain changes to keep your dApp in sync:
// Listen for account changes
window.ethereum.on("accountsChanged", (accounts) => {
if (accounts.length === 0) {
console.log("Wallet disconnected");
} else {
console.log("Account changed:", accounts[0]);
}
});
// Listen for chain changes
window.ethereum.on("chainChanged", (chainId) => {
console.log("Chain changed to:", parseInt(chainId, 16));
// Recommended: reload the page on chain change
window.location.reload();
});
// Listen for connection
window.ethereum.on("connect", (connectInfo) => {
console.log("Connected to chain:", connectInfo.chainId);
});
// Listen for disconnection
window.ethereum.on("disconnect", (error) => {
console.log("Disconnected:", error);
});Important: When the chain changes, it's recommended to reload your application to ensure all state is properly updated. Some dApps may have issues if they don't handle chain changes correctly.