exchange.IO("base", ...)
Set the RPC node address of a Web3 exchange object; on EVM chains several nodes can back each other up.
exchange.IO(k)
exchange.IO(k, address)Examples
-
Switch the RPC node to the BSC chain.
javascriptfunction main() { var chainRpc = "https://bsc-dataseed.binance.org" exchange.IO("base", chainRpc) // Switch to BSC chain } -
Set multiple nodes as backups for each other.
javascriptfunction main() { // Multiple nodes as backups for each other: automatically switch to the next node when a node // is unavailable or rate-limited; nodes whose chainId is inconsistent with the first node will // not be used exchange.IO("base", ["https://bsc-dataseed.bnbchain.org", "https://bsc-rpc.publicnode.com"]) Log("Node:", exchange.IO("base")) Log("Block height:", parseInt(exchange.IO("api", "eth", "eth_blockNumber"), 16)) }
Returns
| Type | Description |
string | When setting, returns the node address in use before the change (a comma-separated string for several nodes); without |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Function of the |
address | string / array | No | Node address. Ethereum (EVM) accepts |
See Also
Remarks
When multiple nodes are set, the node that succeeded in the last request is used first. When a node encounters a connection failure, request timeout, a non-2xx HTTP status code, a response that is not in valid JSON-RPC format, or rate limiting, the system automatically switches to the next node. Normal JSON-RPC errors such as contract execution failure (revert) will not trigger node switching.
The chainId of each node is verified upon its first use. Nodes whose chain is inconsistent with that of the first available node will not be used, in order to avoid sending transactions to other chains. Node addresses in the logs only display the protocol and domain name, and do not include the API Key in the path.
The chain ID is fetched again after switching nodes. Multiple fallback nodes only apply to Ethereum (EVM); TRON does not support them.