1.用到的BNB官方接口地址:
接口一:查询交易状态:
https://docs.bscscan.com/api-endpoints/stats
请求:
https://api.bscscan.com/api ?module=transaction &action=gettxreceiptstatus &txhash=0xe9975702518c79caf81d5da65dea689dcac701fcdd063f848d4f03c85392fd00 &apikey=YourApiKeyToken
响应:
{ "status":"1", "message":"OK", "result":{ "status":"1" } }
接口二:获取交易信息:
https://docs.bscscan.com/api-endpoints/geth-parity-proxy
请求:
https://api.bscscan.com/api ?module=proxy &action=eth_getTransactionByHash &txhash=0x9983332a52df5ad1dabf8fa81b1642e9383f302a399c532fc47ecb6a7a967166 &apikey=YourApiKeyToken
响应:
{ "jsonrpc":"2.0", "id":1, "result":{ "blockHash":"0x4beb0710a78f560687a455d2f0faf4595a306dd5ce46006005eec82c4081efe0", "blockNumber":"0xa11595", "from":"0x25f1358276a9f93feaffeb5bf92e0a62554db3d3", "gas":"0x4e033", "gasPrice":"0x12a05f200", "hash":"0x9983332a52df5ad1dabf8fa81b1642e9383f302a399c532fc47ecb6a7a967166", "input":"0xd3243f25000000000000000000000000000000000000000000000000000000000000153b000000000000000000000000000000000000000000000000000000000000091a", "nonce":"0x2a8", "to":"0x67d9b4921bc8b397d9b0c0ca7274ada50167e7d0", "transactionIndex":"0x10e", "value":"0x0", "type":"0x0", "v":"0x94", "r":"0x26a2b15bae27427462a4ec5830f4b17f5dd51bfaa1e898a6e61207be61d204a7", "s":"0x5e9347d499cee66a021ddb1a38b15dcf106efbc54fa3c8d1929f8c28bcc41188" } }
2.根据hash手动核对的地址
详细信息:https://bscscan.com/tx/hash
3.接口二的信息解读
1.form是发起转账的钱包地址
2.收款方的钱包地址和金额在input中解析,步骤如下:
// 直接从获取到接口数据开始 $input = $arrays['result']['input']; // 解析接收方地址 $toAddressHex = substr($input, 10, 64); // 第 10 到 73 个字符 $toAddress = '0x' . substr($toAddressHex, 24); // 去掉前 24 个字符(填充的零)To Address $fromAddress = $arrays['result']['from']; // From Address // 解析转账金额 $valueHex = substr($input, 74, 64); // 第 74 到 137 个字符 $value = gmp_init($valueHex, 16); // 将十六进制转换为 GMP 对象 // 如果代币的小数位数是 18,将 wei 转换为代币的实际单位 $tokenDecimal = 18; $divisor = gmp_pow('10', $tokenDecimal); $valueInToken = gmp_strval(gmp_div($value, $divisor)); // 代币金额