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

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

Request example:

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

Response example:

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