Ethereum/基本操作

基本操作

本指南涵盖了使用 TheRPC API 在以太坊区块链上执行的最常见操作。

# 检索基本信息

获取最新区块号

{
  "jsonrpc": "2.0",
  "method": "eth_blockNumber",
  "params": [],
  "id": 1
}

更多详情请参阅 eth_blockNumber

检查账户余额

{
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": [
    "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    "latest"
  ],
  "id": 1
}

更多详情请参阅 eth_getBalance

# 交易操作

获取交易状态

{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionByHash",
  "params": [
    "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"
  ],
  "id": 1
}

更多详情请参阅 eth_getTransactionByHash

检查交易收据

{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionReceipt",
  "params": [
    "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"
  ],
  "id": 1
}

更多详情请参阅 eth_getTransactionReceipt

# 区块信息

通过编号获取区块

{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": [
    "0xE81224",
    false
  ],
  "id": 1
}

更多详情请参阅 eth_getBlockByNumber

通过哈希获取区块

{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByHash",
  "params": [
    "0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
    false
  ],
  "id": 1
}

更多详情请参阅 eth_getBlockByHash

# 智能合约交互

调用合约方法

{
  "jsonrpc": "2.0",
  "method": "eth_call",
  "params": [
    {
      "to": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
      "data": "0x70a08231000000000000000000000000742d35Cc6634C0532925a3b844Bc454e4438f44e"
    },
    "latest"
  ],
  "id": 1
}

更多详情请参阅 eth_call

获取合约代码

{
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    "latest"
  ],
  "id": 1
}

更多详情请参阅 eth_getCode

# 网络状态

获取网络版本

{
  "jsonrpc": "2.0",
  "method": "net_version",
  "params": [],
  "id": 1
}

更多详情请参阅 net_version

检查节点同步状态

{
  "jsonrpc": "2.0",
  "method": "eth_syncing",
  "params": [],
  "id": 1
}

更多详情请参阅 eth_syncing

# Gas 和 Nonce

获取 Gas 价格

{
  "jsonrpc": "2.0",
  "method": "eth_gasPrice",
  "params": [],
  "id": 1
}

更多详情请参阅 eth_gasPrice

获取交易计数(Nonce)

{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionCount",
  "params": [
    "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    "latest"
  ],
  "id": 1
}

更多详情请参阅 eth_getTransactionCount

实现示例

有关特定语言的实现,请查看我们的 SDK:

另请参阅

帮助我们变得更好!
分享此页面并帮助我们为您创建更好的产品。