go-ethereum、JSON-RPC、ethclient、infura之间的关系
go-ethereum
用go编写的Geth,支持多种通讯方式:HTTP、Websocket和IPC(geth.ipc)让你通过JSON-RPC与之通信。
JSON-RPC
是一种轻量级的远程过程调用协议,通常运行于 HTTP、WebSocket 等之上。使用JSON作为数据格式。面向操作(资源的方法:method+params),而HTTP则是面向资源(URL)
subscribe := map[string]interface{}{
"jsonrpc": "2.0", // JSON-RPC 协议版本
"id": 1, // 请求标识符
"method": "eth_subscribe", // 要调用的以太坊方法
"params": []any{ // 方法参数
"logs",
map[string]interface{}{
"address": contractAddress,
"topics": []string{transferEvent},
},
},
}
ethclient
是go-ethereum提供的Go语言库,封装了JSON-RPC调用。
Infura
托管以太坊节点的云服务。提供 HTTPS/WebSocket 接口,无需你自己搭建节点。支持主流 EVM 链(Ethereum, Arbitrum, Polygon 等)

浙公网安备 33010602011771号