波场TRC20 TRX 以太坊 ETH ERC20 接口代码分享

Posted debug码农

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了波场TRC20 TRX 以太坊 ETH ERC20 接口代码分享相关的知识,希望对你有一定的参考价值。

生成地址

"code":1,"msg":"ok","data":"privateKey":"8C50998C92A606A686B35A2AEEAAF357A01A478C65E075D700C7FA4A564D9D8A","publicKey":"048AC18DCC9229C742C836F87799EC7E8EC647645D3BCBEF854FA2E6B3639A31C5212E227E1256D8F0B349BBAB10913043CF24B983AF245A2FE0492286BF41439D","address":"base58":"TKghWFS61H6JVjMARpjKGFFe11aGAFfYmJ","hex":"416A91FAD659D2B3E84D93F1FD9B995D4BEC6AD2C0"

TRX交易监控

 "owner_address": "TSSrhM7VRWFZMwPZ4QPqrZULTP4swAkkyW", "to_address": "THK7MrUT6FBCS1RPqgcspY3ehP6pAo7DoN", "txID": "07450f4027f3ab21bf178d36bf57815b73f8e4d2fb8b8c5e0556d1b67cb7ea13", "amount": 4200, "extra":  "ret": [ "contractRet": "SUCCESS" ], "signature": ["84c2cdb5990fc3f6fd46278b9575c646377cdb3190765df4215df056bb4e9741e2dd5cd9f8bfbab5f674469218f2074e73b14a48e9460b7f115df77d8aaa8a0601"], "txID": "07450f4027f3ab21bf178d36bf57815b73f8e4d2fb8b8c5e0556d1b67cb7ea13", "raw_data":  "contract": [ "parameter":  "value":  "amount": 4200, "asset_name": "31303033353333", "owner_address": "41b4bcb59b5a7d446ad2ec0780af85fa36c4ed14ee", "to_address": "41508c7d8edcd6c0eb1f24dbb898cbf610d2e2f789" , "type_url": "type.googleapis.com/protocol.TransferAssetContract" , "type": "TransferAssetContract" ], "ref_block_bytes": "4c96", "ref_block_hash": "00f3655724057d2a", "expiration": 1615975383000, "timestamp": 1615975325824 , "raw_data_hex": "0a024c96220800f3655724057d2a40d8ff8dfd832f5a74080212700a32747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e736665724173736574436f6e7472616374123a0a0731303033353333121541b4bcb59b5a7d446ad2ec0780af85fa36c4ed14ee1a1541508c7d8edcd6c0eb1f24dbb898cbf610d2e2f78920e8207080c18afd832f"   

代币交易监控

 "owner_address": "THkmAtkdj3zp9FBzv8dBT4iEPX4qgP6xFh", "to_address": "TPEB1wuJ6EvJBaFjANsppQ2geqKVV8TMxE", "txID": "ad7b37ce3f04b5531f1cf9e1e561f2baefa21f4d1b064f94bd064be2e472fcf9", "amount": 1650.52, "extra":  "block": 28527969, "timestamp": 1615975878000, "contract": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "name": "Transfer", "transaction": "ad7b37ce3f04b5531f1cf9e1e561f2baefa21f4d1b064f94bd064be2e472fcf9", "result":  "0": "0x556673dad4114df924fd0e161195dde4594bb80a", "1": "0x916e37c7635f9552316ee7cec1599d8ff0bb03c3", "2": "1650520000", "from": "0x556673dad4114df924fd0e161195dde4594bb80a", "to": "0x916e37c7635f9552316ee7cec1599d8ff0bb03c3", "value": "1650520000" , "resourceNode": "fullNode", "unconfirmed": true   

代码 波场的代码

<?php 

    require_once './config/config.php';
    
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '' ;
    if($action == 'generateAddress' )
        $url = trx_server_api . "/generate_address";
        $resp = RequestPOSTData($url);
        echo "<p>请求波场生成地址响应如下:</p>";
        echo $resp; 
        exit;
    
    if ( $action == 'isAddress' )
        $url = trx_server_api . "/isAddress";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $resp = RequestPOSTData($url , ['address' => $address] ) ; 
        echo "<p>检测地址是否正确响应结果:</p>";
        echo $resp ; 
        exit;
    
    
    
    if ( $action == 'trx_trans' )
        $url = trx_server_api . "/trx_trans";
        $from_address_private = isset($_REQUEST['from_address_private']) ? trim($_REQUEST['from_address_private']) : '';
        $fromAddress = isset($_REQUEST['fromAddress']) ? trim($_REQUEST['fromAddress']) : '';
        $toAddress = isset($_REQUEST['toAddress']) ? trim($_REQUEST['toAddress']) : '';
        $amount = isset($_REQUEST['amount']) ? trim($_REQUEST['amount']) : '';
        $resp = RequestPOSTData($url , [
            'from_address_private' => $from_address_private ,
            'fromAddress' => $fromAddress , 
            'toAddress' => $toAddress,
            'amount' => $amount,
            'remark' => '测试'
            ] ) ; 
        echo "<p>波场转账结果:</p>";
        echo $resp ; 
        exit;
    
    
    if ( $action == 'token_trans' )
        $url = trx_server_api . "/trc20_trans";
        $from_address_private = isset($_REQUEST['from_address_private']) ? trim($_REQUEST['from_address_private']) : '';
        $fromAddress = isset($_REQUEST['fromAddress']) ? trim($_REQUEST['fromAddress']) : '';
        $toAddress = isset($_REQUEST['toAddress']) ? trim($_REQUEST['toAddress']) : '';
        $amount = isset($_REQUEST['amount']) ? trim($_REQUEST['amount']) :  0 ;
        $contract_address = isset($_REQUEST['contract_address']) ? trim($_REQUEST['contract_address']) : '';
        $resp = RequestPOSTData($url , [
            'from_address_private' => $from_address_private ,
            'fromAddress' => $fromAddress , 
            'toAddress' => $toAddress,
            'amount' => bcmul( $amount , pow(10 , 6 ))   ,//注意 这个地方要乘以精度 尤其注意 
            'contract_address' => $contract_address,
            ] ) ; 
        //echo "<p>以太坊代币转账结果:</p>";
        echo $resp ; 
        exit;
    
    
    
    if ( $action == 'trx_get_money' )
        $url = trx_server_api . "/trx_get_money";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $resp = RequestPOSTData($url , [
            'address' => $address ,
            
            ] ) ; 
        echo "<p>波场的TRX数查询结果:</p>";
        echo $resp ; 
        exit;
    
    
    
    
    if ( $action == 'trx_token_get_money' )
        $url = trx_server_api . "/trx_token_get_money";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $contract_address = isset($_REQUEST['contract_address']) ? trim($_REQUEST['contract_address']) : '';
        $resp = RequestPOSTData($url , [
            'address' => $address ,
            'contract_address' => $contract_address,
            'contract_abi' => $contract_abi
            
            ] ) ; 
        echo "<p>波场代币数查询结果:</p>";
        echo $resp ; 
        exit;
    
    
    if ( $action == 'trx_GetTransactionById' )
        $url = trx_server_api . "/GetTransactionById";
        $trxid = isset($_REQUEST['trxid']) ? trim($_REQUEST['trxid']) : '';
        $resp = RequestPOSTData($url , [
            'trxid' => $trxid ,
         
            ] ) ; 
        echo "<p>根据波场交易ID查询交易结果返回数据:</p>";
        echo $resp ; 
        exit;
    
    if ( $action == 'transactionsTrc20List' )
        $url = trx_server_api . "/transactionsTrc20List";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $resp = RequestPOSTData($url , [
            'address' => $address ,
            'num' => 200 
         
            ] ) ; 
        echo "<p>查询代币的最新记录返回结果:</p>";
        echo $resp ; 
        exit;
    
    if ( $action == 'save_check_address' )
        $url = trx_server_api . "/save_check_address";
        $address_str = isset($_REQUEST['address_str']) ? trim($_REQUEST['address_str']) : '';
        if( empty($address_str))
            exit("缺失监控地址");
        
        $data = [];
        $address_str = explode("\\n" , $address_str);
        foreach ($address_str as $item )
            $item  = trim($item );
            if( empty($item ))
                continue ; 
            
            $data[] = $item ;
        
       
        $resp = RawRequestData(  $url , $data  ) ; 
        echo "<p>保存要监控的地址返回结果如下:</p>";
        echo $resp ; 
        exit;
    
    
    
    
    
    
    
    
    
    
?>

<html lang="zh_cn" data-index="">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>波场</title>
    <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css">

    <!-- Bootstrap -->
    
    <body>
        
        
        <ul class="nav nav-pills">
          <li role="presentation" ><a href="/">首页</a></li>
          <li role="presentation" class="active"><a href="#">波场</a></li>
        </ul>
        
        <h1 style="color:red;" class="alert alert-success"><center>波场的可以使用测试网络测试 , 如果要正式环境测试 , 请修改配置文件 conf/config.js 然后重启服务即可</center></h1>
        
        
        <div class="col-md-12" >
            <h1 class="page-header">1.生成波场钱包地址</h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="generateAddress"></p>
                    <p><input type="submit" value="点击我发送post请求生成" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
       
         <div class="col-md-12" >
            <h1>2.检测地址是否正确</h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="isAddress"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">钱包地址</span>
                          <input type="text" class="form-control" name="address" >
                        </div>
                    </p>
                    <p><input type="submit" value="检测点我" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12"  >
            <h1>3.TRX转账</h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p>
                        <input type="hidden" name="action" value="trx_trans"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">从谁转</span>
                          <input type="text" class="form-control" name="fromAddress" >
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">来源地址私钥</span>
                          <input type="text" class="form-control" name="from_address_private" >
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">给谁</span>
                          <input type="text" class="form-control" name="toAddress" >
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">转出数量</span>
                          <input type="text" class="form-control" name="amount" >
                        </div>
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        
        <div class="col-md-12" >
            <h1>4.波场代币转账</h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="token_trans"></p>
                    
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">从谁转</span>
                          <input type="text" class="form-control" name="fromAddress" value="">
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">来源地址私钥</span>
                          <input type="text" class="form-control" name="from_address_private" value="">
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">给谁</span>
                          <input type="text" class="form-control" name="toAddress" value="">
                        </div>
                        
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">转出金额</span>
                          <input type="text" class="form-control" name="amount" value="">
                        </div>
                        
                    </p>
                    
                    
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约地址</span>
                          <input type="text" class="form-control" name="contract_address" value="">
                          
                        </div>
                        usdt的合约地址是:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12" >
            <h1>5.根据地址查询TRX数</h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="trx_get_money"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">地址</span>
                          <input type="text" class="form-control" name="address" value="" >
                        </div>
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12" >
            <h1>6.根据地址查询合约的代币数 【比如查询多少个USDT】</h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="trx_token_get_money"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">地址</span>
                          <input type="text" class="form-control" name="address" value="" >
                        </div>
                    </p>
                     <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约地址</span>
                          <input type="text" class="form-control" name="contract_address" value="">
                        </div>
                        
                        usdt的合约地址是:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        
         <div class="col-md-12" >
            <h1>7.根据交易hash查询交易 </h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="trx_GetTransactionById"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">交易ID</span>
                          <input type="text" class="form-control" name="trxid" value="" >
                        </div>
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
         <div class="col-md-12" >
            <h1>8.获取最新的历史交易记录 【代币 比如USDT】 </h1>
            
            <div>
                <form action="/trx.php" method="POST">
                    <p><input type="hidden" name="action" value="transactionsTrc20List"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">钱包地址</span>
                          <input type="text" class="form-control" name="address" value="" >
                        </div>
                    </p>
                    <p><input type="submit" value="查询" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12" >
            <div class="jumbotron">
              <h1>监控!</h1>
              <p>1:可以监控波场地址的 TRX交易 和  代币交易 比如USDT交易,监控之后 会通知到设置的回调地址上面</p>
              <p>2:可以在配置文件设置 通知的地址 </p>
              <p>3:接收异步通知 Content-Type是:application/json 请求method:POST</p>
              <p>
                  <div class="col-md-12" >
                    <h2 style="color:green">a.设置要监控的地址 </h2>
                    
                    <div>
                        <form action="/trx.php" method="POST">
                            <p><input type="hidden" name="action" value="save_check_address"></p>
                            <p>
                                <div class="input-group">
                                  <span class="input-group-addon" id="basic-addon3">钱包地址,一行一个</span>
                                  <textarea class="form-control" name="address_str"></textarea>
                                </div>
                            </p>
                            <p><input type="submit" value="保存需要监控的地址" class="btn btn-primary btn-lg btn btn-success"></p>
                        </form>
                    </div>
                </div>    
              </p>
              
              <p>
                  <h2 style="color:green">b.TRX交易监控结果 </h2>
                <div class="alert alert-success" role="alert">
                    
    
    	"owner_address": "TSSrhM7VRWFZMwPZ4QPqrZULTP4swAkkyW",
    	"to_address": "THK7MrUT6FBCS1RPqgcspY3ehP6pAo7DoN",
    	"txID": "07450f4027f3ab21bf178d36bf57815b73f8e4d2fb8b8c5e0556d1b67cb7ea13",
    	"amount": 4200,
    	"extra": 
    		"ret": [
    			"contractRet": "SUCCESS"
    		],
    		"signature": ["84c2cdb5990fc3f6fd46278b9575c646377cdb3190765df4215df056bb4e9741e2dd5cd9f8bfbab5f674469218f2074e73b14a48e9460b7f115df77d8aaa8a0601"],
    		"txID": "07450f4027f3ab21bf178d36bf57815b73f8e4d2fb8b8c5e0556d1b67cb7ea13",
    		"raw_data": 
    			"contract": [
    				"parameter": 
    					"value": 
    						"amount": 4200,
    						"asset_name": "31303033353333",
    						"owner_address": "41b4bcb59b5a7d446ad2ec0780af85fa36c4ed14ee",
    						"to_address": "41508c7d8edcd6c0eb1f24dbb898cbf610d2e2f789"
    					,
    					"type_url": "type.googleapis.com/protocol.TransferAssetContract"
    				,
    				"type": "TransferAssetContract"
    			],
    			"ref_block_bytes": "4c96",
    			"ref_block_hash": "00f3655724057d2a",
    			"expiration": 1615975383000,
    			"timestamp": 1615975325824
    		,
    		"raw_data_hex": "0a024c96220800f3655724057d2a40d8ff8dfd832f5a74080212700a32747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e736665724173736574436f6e7472616374123a0a0731303033353333121541b4bcb59b5a7d446ad2ec0780af85fa36c4ed14ee1a1541508c7d8edcd6c0eb1f24dbb898cbf610d2e2f78920e8207080c18afd832f"
    	
    
    
                </div>
    
            </p>
            
            <p>
                 <h2 style="color:green">c.代币比如USDT交易监控结果 </h2>
                <div class="alert alert-success" role="alert">
                    
                
    
    	"owner_address": "THkmAtkdj3zp9FBzv8dBT4iEPX4qgP6xFh",
    	"to_address": "TPEB1wuJ6EvJBaFjANsppQ2geqKVV8TMxE",
    	"txID": "ad7b37ce3f04b5531f1cf9e1e561f2baefa21f4d1b064f94bd064be2e472fcf9",
    	"amount": 1650.52,
    	"extra": 
    		"block": 28527969,
    		"timestamp": 1615975878000,
    		"contract": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
    		"name": "Transfer",
    		"transaction": "ad7b37ce3f04b5531f1cf9e1e561f2baefa21f4d1b064f94bd064be2e472fcf9",
    		"result": 
    			"0": "0x556673dad4114df924fd0e161195dde4594bb80a",
    			"1": "0x916e37c7635f9552316ee7cec1599d8ff0bb03c3",
    			"2": "1650520000",
    			"from": "0x556673dad4114df924fd0e161195dde4594bb80a",
    			"to": "0x916e37c7635f9552316ee7cec1599d8ff0bb03c3",
    			"value": "1650520000"
    		,
    		"resourceNode": "fullNode",
    		"unconfirmed": true
    	
    
    
    
                </div>
    
            </p>
            
            
            </div>
        
        </div>
        
        
    </body>
    
</html>

以太坊代码

<?php 

    require_once './config/config.php';
    
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '' ;
    if($action == 'generateAddress' )
        $url = eth_server_api . "/eth_generate_address";
        $resp = RequestPOSTData($url);
        echo "<p>请求以太坊生成地址响应如下:</p>";
        echo $resp; 
        exit;
    
   
    if ( $action == 'isAddress' )
        $url = eth_server_api . "/isAddress";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $resp = RequestPOSTData($url , ['address' => $address] ) ; 
        echo "<p>检测地址是否正确响应结果:</p>";
        echo $resp ; 
        exit;
    
    
    if ( $action == 'eth_trans' )
        $url = eth_server_api . "/eth_trans";
        $from_address_private = isset($_REQUEST['from_address_private']) ? trim($_REQUEST['from_address_private']) : '';
        $fromAddress = isset($_REQUEST['fromAddress']) ? trim($_REQUEST['fromAddress']) : '';
        $toAddress = isset($_REQUEST['toAddress']) ? trim($_REQUEST['toAddress']) : '';
        $amount = isset($_REQUEST['amount']) ? trim($_REQUEST['amount']) : '';
        $resp = RequestPOSTData($url , [
            'from_address_private' => $from_address_private ,
            'fromAddress' => $fromAddress , 
            'toAddress' => $toAddress,
            'amount' => $amount
            ] ) ; 
        echo "<p>ETH转账结果:</p>";
        echo $resp ; 
        exit;
    
    if ( $action == 'estimateEth' )
        $url = eth_server_api . "/estimateEth";
        $fromAddress = isset($_REQUEST['fromAddress']) ? trim($_REQUEST['fromAddress']) : '';
        $toAddress = isset($_REQUEST['toAddress']) ? trim($_REQUEST['toAddress']) : '';
        $amount = isset($_REQUEST['amount']) ? trim($_REQUEST['amount']) :  0 ;
        $contract_address = isset($_REQUEST['contract_address']) ? trim($_REQUEST['contract_address']) : '';
        $contract_abi = isset($_REQUEST['contract_abi']) ? trim($_REQUEST['contract_abi']) : '';
        $resp = RequestPOSTData($url , [
            'from_address_private' => $from_address_private ,
            'fromAddress' => $fromAddress , 
            'toAddress' => $toAddress,
            'amount' => bcmul( $amount , pow(10 , 6 ))   , //这个地方要乘以精度
            'contract_address' => $contract_address,
            'contract_abi' => $contract_abi
            ] ) ; 
        echo "<p>以太坊转账预估消耗的ETH数:</p>";
        echo $resp ; 
        exit;
    
    if ( $action == 'token_trans' )
        $url = eth_server_api . "/eth_token_trans";
        $from_address_private = isset($_REQUEST['from_address_private']) ? trim($_REQUEST['from_address_private']) : '';
        $fromAddress = isset($_REQUEST['fromAddress']) ? trim($_REQUEST['fromAddress']) : '';
        $toAddress = isset($_REQUEST['toAddress']) ? trim($_REQUEST['toAddress']) : '';
        $amount = isset($_REQUEST['amount']) ? trim($_REQUEST['amount']) :  0 ;
        $contract_address = isset($_REQUEST['contract_address']) ? trim($_REQUEST['contract_address']) : '';
        $contract_abi = isset($_REQUEST['contract_abi']) ? trim($_REQUEST['contract_abi']) : '';
        $resp = RequestPOSTData($url , [
            'from_address_private' => $from_address_private ,
            'fromAddress' => $fromAddress , 
            'toAddress' => $toAddress,
            'amount' => bcmul( $amount , pow(10 , 6 ))   ,
            'contract_address' => $contract_address,
            'contract_abi' => $contract_abi
            ] ) ; 
        echo "<p>以太坊代币转账结果:</p>";
        echo $resp ; 
        exit;
    
    
    
    
    
    
    if ( $action == 'eth_get_money' )
        $url = eth_server_api . "/eth_get_money";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $resp = RequestPOSTData($url , [
            'address' => $address ,
            
            ] ) ; 
        echo "<p>ETH数查询结果:</p>";
        echo $resp ; 
        exit;
    
    
    
    
    if ( $action == 'eth_token_get_money' )
        $url = eth_server_api . "/eth_token_get_money";
        $address = isset($_REQUEST['address']) ? trim($_REQUEST['address']) : '';
        $contract_address = isset($_REQUEST['contract_address']) ? trim($_REQUEST['contract_address']) : '';
        $contract_abi = isset($_REQUEST['contract_abi']) ? trim($_REQUEST['contract_abi']) : '';
        $resp = RequestPOSTData($url , [
            'address' => $address ,
            'contract_address' => $contract_address,
            'contract_abi' => $contract_abi
            
        ]); 
        echo "<p>以太坊代币数查询结果:</p>";
        echo $resp ; 
        exit;
    
    
    if ( $action == 'eth_GetTransactionById' )
        $url = eth_server_api . "/eth_GetTransactionById";
        $trxid = isset($_REQUEST['trxid']) ? trim($_REQUEST['trxid']) : '';
        $resp = RequestPOSTData($url , [
            'trxid' => $trxid ,
         
            ] ) ; 
        echo "<p>根据以太坊交易ID查交易状态:</p>";
        echo $resp ; 
        exit;
    
    
    
    if ( $action == 'save_check_address' )
        $url = eth_server_api . "/save_check_address";
        $address_str = isset($_REQUEST['address_str']) ? trim($_REQUEST['address_str']) : '';
        if( empty($address_str))
            exit("缺失监控地址");
        
        $data = [];
        $address_str = explode("\\n" , $address_str);
        foreach ($address_str as $item )
            $item  = trim($item );
            if( empty($item ))
                continue ; 
            
            $data[] = $item ;
        
       
        $resp = RawRequestData(  $url , $data  ) ; 
        echo "<p>保存要监控的地址返回结果如下:</p>";
        echo $resp ; 
        exit;
    
    
    
    
    
    
    
?>

<html lang="zh_cn" data-index="">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>以太坊</title>
    <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css">

    <!-- Bootstrap -->
    
    <body>
        <ul class="nav nav-pills">
          <li role="presentation" ><a href="/">首页</a></li>
          <li role="presentation" class="active"><a href="#">以太坊</a></li>
        </ul>
        
        
        <h1 style="color:red;" class="alert alert-success"><center>以太坊可以使用测试环境测试 ,, 如果要正式环境测试 , 请修改配置文件 conf/config.js 然后重启服务即可</center></h1>
        
        
        <div class="col-md-12" >
            <h1 class="page-header">1.生成以太坊地址</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="generateAddress"></p>
                    <p><input type="submit" value="点击我发送post请求生成" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
       
       <div class="col-md-12" >
            <h1>2.检测地址是否正确</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="isAddress"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">钱包地址</span>
                          <input type="text" class="form-control" name="address" >
                        </div>
                    </p>
                    <p><input type="submit" value="检测点我" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>

        
        <div class="col-md-12"  >
            <h1>3.ETH转账</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p>
                        <input type="hidden" name="action" value="eth_trans"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">从谁转</span>
                          <input type="text" class="form-control" name="fromAddress" >
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">来源地址私钥</span>
                          <input type="text" class="form-control" name="from_address_private" >
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">给谁</span>
                          <input type="text" class="form-control" name="toAddress" >
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">转出数量</span>
                          <input type="text" class="form-control" name="amount" >
                        </div>
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12" >
            <h1>4.以太坊代币转账 预估消耗的ETH数</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="estimateEth"></p>
                    
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">从谁转</span>
                          <input type="text" class="form-control" name="fromAddress" value="">
                        </div>
                    </p>
                   
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">给谁</span>
                          <input type="text" class="form-control" name="toAddress" value="">
                        </div>
                        
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">转出金额</span>
                          <input type="text" class="form-control" name="amount" value="">
                        </div>
                        
                    </p>
                    
                    
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约地址</span>
                          <input type="text" class="form-control" name="contract_address" value="">
                        </div>
                        
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约ABI代码</span>
                          <textarea class="form-control" name="contract_abi" rows="3"></textarea>
                        </div>
                        
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        <div class="col-md-12" >
            <h1>5.以太坊代币转账</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="token_trans"></p>
                    
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">从谁转</span>
                          <input type="text" class="form-control" name="fromAddress" value="">
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">来源地址私钥</span>
                          <input type="text" class="form-control" name="from_address_private" value="">
                        </div>
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">给谁</span>
                          <input type="text" class="form-control" name="toAddress" value="">
                        </div>
                        
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">转出金额</span>
                          <input type="text" class="form-control" name="amount" value="">
                        </div>
                        
                    </p>
                    
                    
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约地址</span>
                          <input type="text" class="form-control" name="contract_address" value="">
                        </div>
                        
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约ABI代码</span>
                          <textarea class="form-control" name="contract_abi" rows="3"></textarea>
                        </div>
                        
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12" >
            <h1>6.根据地址查询eth数</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="eth_get_money"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">地址</span>
                          <input type="text" class="form-control" name="address" value="" >
                        </div>
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        <div class="col-md-12" >
            <h1>7.根据地址查询合约的代币数</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="eth_token_get_money"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">地址</span>
                          <input type="text" class="form-control" name="address" value="" >
                        </div>
                    </p>
                     <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约地址</span>
                          <input type="text" class="form-control" name="contract_address" value="">
                        </div>
                        
                    </p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">合约ABI代码</span>
                          <textarea class="form-control" name="contract_abi" rows="3"></textarea>
                        </div>
                        
                        
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        
        
         <div class="col-md-12" >
            <h1>8.根据交易hash查询交易 状态</h1>
            
            <div>
                <form action="/eth.php" method="POST">
                    <p><input type="hidden" name="action" value="eth_GetTransactionById"></p>
                    <p>
                        <div class="input-group">
                          <span class="input-group-addon" id="basic-addon3">交易ID</span>
                          <input type="text" class="form-control" name="trxid" value="" >
                        </div>
                    </p>
                    <p><input type="submit" value="保存提交" class="btn btn-primary btn-lg"></p>
                </form>
            </div>
        </div>
        
        <div class="col-md-12" >
            <div class="jumbotron">
              <h1>九:监控!</h1>
              <p>1:可以监控波场地址的 ETH交易 和  代币交易 比如USDT交易,监控之后 会通知到设置的回调地址上面</p>
              <p>2:可以在配置文件设置 通知的地址 </p>
              <p>3:接收异步通知 Content-Type是:application/json 请求method:POST</p>
              <p>
                  <div class="col-md-12" >
                    <h2 style="color:green">a.设置要监控的地址 </h2>
                    
                    <div>
                        <form action="/eth.php" method="POST">
                            <p><input type="hidden" name="action" value="save_check_address"></p>
                            <p>
                                <div class="input-group">
                                  <span class="input-group-addon" id="basic-addon3">钱包地址,一行一个</span>
                                  <textarea class="form-control" name="address_str"></textarea>
                                </div>
                            </p>
                            <p><input type="submit" value="保存需要监控的地址" class="btn btn-primary btn-lg btn btn-success"></p>
                        </form>
                    </div>
                </div>    
              </p>
              </div>
        </div>
    </body>
    
</html>

代码下载地址 测试地址http://blockchainapi.dapp.nohup88.com/

以上是关于波场TRC20 TRX 以太坊 ETH ERC20 接口代码分享的主要内容,如果未能解决你的问题,请参考以下文章

以太坊 USDT-ERC20合约 注释版

以太坊 USDT-ERC20合约 注释版

以太坊私链部署erc20_usdt代币

Ethereum以太坊ERC20 Token标准完整说明

以太坊dapp智能合约ERC20的生态教程

用 Parity 发送 ERC20 Token