JSONRPC调用以太坊

端口号是 在进入终端时 命令行中 --rpcport 8545这里设置的

String url="http://127.0.0.1:8545";
        
        //查看geth客户端版本
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":67}";
        
        //查看账户
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"eth_accounts\",\"params\":null,\"id\":1}";
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"eth_coinbase\",\"params\":null,\"id\":2}";
        //查看账户余额
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBalance\",\"params\":[\"0x41d6d5a2288cc4d56f5090c028eebc39fa9cc210\",\"latest\"],\"id\":3}";
        //创建账号
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"personal_newAccount\",\"params\":[\"123123\"],\"id\":4}";
        //查看所有账号
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"personal_listAccounts\",\"params\":null,\"id\":5}";
        //解锁账户
//        String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"personal_unlockAccount\",\"params\":[\"0x41d6d5a2288cc4d56f5090c028eebc39fa9cc210\",\"123123\"],\"id\":4}"; 
        //交易
//      String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{\"from\":\"0x41d6d5a2288cc4d56f5090c028eebc39fa9cc210\",\"to\": \"0x8ccac9a996281af1c2f1512485ce852319e16cbe\",\"value\":\"0xcddddd\" }],\"id\":5}";
        //查询交易信息
//    String paramJson="{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"0x2e88ea5cd27171c5d9c76971a85b26928149ec700a488d90676c63348c4ea165\"],\"id\":1}";
      
        
      //调用智能合约
        String paramJson = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{\"from\":\"0x9bdfee3a498e9d70ae37161d53e56f6546bc5257\",\"to\": \"0x3d3161f2b674834756692e7662bb418c85c22a66\",\"data\":\"0x867904b40000000000000000000000009bdfee3a498e9d70ae37161d53e56f6546bc5257000000000000000000000000000000000000000000000000000000000000000a\"}],\"id\":67}";
 

请求时候用post方式请求

        String response = doJsonPost(url,paramJson);
        
        System.out.println(response) ;
        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值