以太坊RPC调用智能合约

geth命令开启rpc

geth --datadir /apps/ethereum/etherdata/  --rpc --rpcapi "db,eth,net,web3" --networkid 15 --identity "alle1nNode" --rpcport 8545 --port 30303   console

注:出于安全考虑,接口默认开放API子集,通过相应参数可以进行配置。

1、 调用RPC接口

# 查看账户信息

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"eth_accounts","params":[],"id":67}' 172.25.0.10:8545

# 查看账户余额

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"eth_getBalance","params":["0xde1e758511a7c67e7db93d1c23c1060a21db4615","latest"],"id":67}' 172.25.0.10:8545

# 查看区块高度

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"eth_blockNumber","params":[],"id":67}' 172.25.0.10:8545

# 解锁账户

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"personal_unlockAccount","params":["0xde1e758511a7c67e7db93d1c23c1060a21db4615","password",300],"id":67}' 172.25.0.10:8545

# 发送交易


curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params": [{                                                                               
  "from": "0xde1e758511a7c67e7db93d1c23c1060a21db4615",
  "to": "0xd64a66c28a6ae5150af5e7c34696502793b91ae7",
  "value": "0x1"
}],
"id":67}' 172.25.0.10:8545

# 查看交易状态

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"miner_start","params":[],"id":67}' 172.25.0.10:8545

# 开启挖矿

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"miner_start","params":[],"id":67}' 172.25.0.10:8545

# 结束挖矿

curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0", "method":"miner_stop","params":[],"id":67}' 172.25.0.10:8545

 

你可能感兴趣的:(区块链技术)