07.4 · API
Wallet methods
Add Galileo or mainnet, then ask for accounts. No signature is required to read a balance.
An injected EIP-1193 provider is window.ethereum. The faucet desk calls wallet_addEthereumChain with the objects below. If the chain is already present, wallet_switchEthereumChain is the fallback.
01
wallet_addEthereumChain
WALLETAdd Galileo. chainId must be the hex of 16602.
Request
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [{
chainId: "0x40da",
chainName: "0G-Galileo-Testnet",
nativeCurrency: { name: "0G", symbol: "0G", decimals: 18 },
rpcUrls: ["https://evmrpc-testnet.0g.ai"],
blockExplorerUrls: ["https://chainscan-galileo.0g.ai"]
}]
});Response
null on success. The wallet then shows 0G-Galileo-Testnet as the active network.- 0x40da is 16602. Do not send 0x40EA. That integer is 16618, a different chain.
02
wallet_addEthereumChain
WALLETAdd mainnet. chainId must be the hex of 16661.
Request
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [{
chainId: "0x4115",
chainName: "0G Mainnet",
nativeCurrency: { name: "0G", symbol: "0G", decimals: 18 },
rpcUrls: ["https://evmrpc.0g.ai"],
blockExplorerUrls: ["https://chainscan.0g.ai"]
}]
});Response
null on success.- 0x4115 is 16661. 0x412D is 16685 and is not this network.
03
eth_requestAccounts
WALLETAsk the wallet which account the person is willing to share.
Request
const accounts = await window.ethereum.request({
method: "eth_requestAccounts"
});Response
["0xabc…"]- Reading a balance does not need this call. You can paste an address into the faucet desk. Request accounts only when you are about to send a transaction.