Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

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.

    javascript
    function main() { var chainRpc = "https://bsc-dataseed.binance.org" exchange.IO("base", chainRpc) // Switch to BSC chain }
  • Set multiple nodes as backups for each other.

    javascript
    function 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

TypeDescription

string

When setting, returns the node address in use before the change (a comma-separated string for several nodes); without address, returns the current node address.

Arguments

NameTypeRequiredDescription

k

string

Yes

Function of the exchange.IO() function. When set to base, it indicates that the function is used to switch RPC nodes.

address

string / array

No

Node address. Ethereum (EVM) accepts http(s):// and ws(s):// addresses; to set several nodes, pass an array of addresses or a string separated by commas (spaces or newlines also work). TRON only accepts a single full-node HTTP address, and passing several addresses (an array or a comma-separated string) is an error; the legacy gRPC addresses grpc.trongrid.io:50051, grpc.nile.trongrid.io:50051 and grpc.shasta.trongrid.io:50051 are mapped to the corresponding HTTP addresses, and any other non-HTTP address is an error. When omitted, only the current node address is queried.

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.