更新时间:2023-08-09 GMT+08:00

使用web3.js发送JSON-RPC API请求

Request example:

const Web3 = require('web3');
const url = 'https://your-http-endpoint/your-credential'
const web3 = new Web3(new Web3.providers.HttpProvider(url));
web3.eth.getBlockNumber((error, blockNumber) => {
	if(!error) {
		console.log(blockNumber);
	} else {
		console.log(error);
	}
});

Response example:

{
"jsonrpc": "2.0",
"id": 1,
"result": "00f3c34b"
}