使用infura 提供的 API获取以太坊交易记录

版权声明:学习中。。。 https://blog.csdn.net/fangdengfu123/article/details/82621537
参数说明
var config = {
    // 网络地址           主网                           rinkeby测试网
    net: ['https://mainnet.infura.io/v3/', 'https://rinkeby.infura.io/v3/'],
    // 浏览器地址         主网                           rinkeby测试网
    scan: ['https://etherscan.io/', 'https://rinkeby.etherscan.io/'],
    // 数据查询api地址    主网                           rinkeby测试网
    api: ['http://api.etherscan.io/api', 'http://api-rinkeby.etherscan.io/api'],
}

// 网络地址
var net = 'https://mainnet.infura.io/v3/';

// 浏览器地址
var scan = 'https://etherscan.io/';

// api地址
var url = 'http://api.etherscan.io/api';

// infura提供的apikey
var apikey = 'c132****66a44****274****7033a7c3';
统一接口地址
http://api.etherscan.io/api
统一返回结果
{
  "status": "1",                     // 返回状态码:1 代表成功,其它代表失败
  "message": "OK",                   // 返回信息
  "result": [
    {
      "blockNumber": "5954979",             // 区块编号
      "timeStamp": "1531459524",            // 时间戳
      "hash": "0xfe8e96138e6c7faee5e4a6cc3530d868e1c8ba687f7b41513a1f1f314c585e01",   // 交易hash
      "nonce": "0",                                                                   // 交易序号
      "blockHash": "0x595ffe8342b87fbbd12dfcd945fd1d5867c70b1d49cb106df4861ae545391d0d", // 区块hash
      "from": "0xe5f28b45908e8b8a34689305c29adc79997653c0",                           // 交易发起方地址
      "contractAddress": "0x744edac3dde8046926eb2ce2be391be1f45ae3eb",                // 合约地址
      "to": "0x6b0c930f19d2153cc1f614aef586047b67674d00",                             // 交易收款方地址
      "value": "150000000000000000000",                                               // 交易额度
      "tokenName": "",                                                     
      "tokenSymbol": "",
      "tokenDecimal": "",
      "transactionIndex": "61",

      "isError": "0",          // 是否发生错误(0:无错误,1:有错误。查看账户整体交易记录时才有。)
      "txreceipt_status": "1",  // 交易接收状态(1:交易成功上链,0:交易没有上链。查看账户整体交易记录时才有。)

      "gas": "200000",                                                               // 手续费上限
      "gasPrice": "16379999999",                                                     // 手续费价格
      "gasUsed": "69325",                                                            // 实际花费手续费
      "cumulativeGasUsed": "1936120",                                                
      "input": "0x00000000000000000000000000000000000000000000000000000000000000046d61726b00000000000000000000000000000000000000000000000000000000",                                                    // 调用合约入参
      "confirmations": "350353"
    },
    {
      "blockNumber": "5991711",
      "timeStamp": "1531996801",
      "hash": "0x315566bf8309bf810b1dd651d2ac2c204889485f5196a0b01018f5837f86f23f",
      "nonce": "16",
      "blockHash": "0x75325ae6ba511b895d3353ffce23e46918e49a806ca0100f475761080f1085d2",
      "from": "0x6b0c930f19d2153cc1f614aef586047b67674d00",
      "contractAddress": "0x744edac3dde8046926eb2ce2be391be1f45ae3eb",
      "to": "0xca9103032a46edda3c24f20f0e9e0bcaef41b578",
      "value": "10",
      "tokenName": "",
      "tokenSymbol": "",
      "tokenDecimal": "",
      "transactionIndex": "178",
      "gas": "100000",
      "gasPrice": "4000000000",
      "gasUsed": "52641",
      "cumulativeGasUsed": "5379501",
      "input": "0xa9059cbb000000000000000000000000ca9103032a46edda3c24f20f0e9e0bcaef41b578000000000000000000000000000000000000000000000000000000000000000a",
      "confirmations": "313621"
    }
  ]
}
获取指定地址内的普通交易

接口参数:

var data = {
    module: 'account',                 // 模块类别
    action: 'txlist',                  // 请求接口
    address: '',                       // 请求参数:钱包地址
    startblock: 0,                     // 请求参数:查询起始区块
    endblock: 999999999,               // 请求参数:查询结束区块
    sort: 'desc',                      // 请求参数:排序类别
    apikey: apikey                     // 请求参数:apikey
}
分页获取普通交易数据

请求参数:

var data = {
    module: 'account',                 // 模块类别
    action: 'txlist',                  // 请求接口
    address: '',                       // 请求参数:钱包地址
    startblock: 0,                     // 请求参数:查询起始区块
    endblock: 999999999,               // 请求参数:查询结束区块
    page: 1,                           // 分页页码
    offset10,                       // 偏移量(每页数量)
    sort: 'desc',                      // 请求参数:排序类别
    apikey: apikey                     // 请求参数:apikey
}
获取代币交易数据

请求参数:

var data = {
    module: 'account',                 // 模块类别
    action: 'tokentx',                  // 请求接口
    address: '',                       // 请求参数:钱包地址
    startblock: 0,                     // 请求参数:查询起始区块
    endblock: 999999999,               // 请求参数:查询结束区块
    sort: 'desc',                      // 请求参数:排序类别
    apikey: apikey                     // 请求参数:apikey
}
分页获取指定代币合约的交易数据
var data = {
    module: 'account',                 // 模块类别
    action: 'tokentx',                  // 请求接口
    contractaddress: '',                // 请求参数:代币合约地址
    startblock: 0,                     // 请求参数:查询起始区块
    endblock: 999999999,               // 请求参数:查询结束区块
    page: 1,                           // 分页页码
    offset10,                       // 偏移量(每页数量)
    sort: 'desc',                      // 请求参数:排序类别
    apikey: apikey                     // 请求参数:apikey
}
分页获取指定地址在指定合约内的交易数据
var data = {
    module: 'account',                 // 模块类别
    action: 'tokentx',                  // 请求接口
    address: '',                       // 请求参数:钱包地址
    contractaddress: '',                // 请求参数:代币合约地址
    startblock: 0,                     // 请求参数:查询起始区块
    endblock: 999999999,               // 请求参数:查询结束区块
    page: 1,                           // 分页页码
    offset10,                       // 偏移量(每页数量)
    sort: 'desc',                      // 请求参数:排序类别
    apikey: apikey                     // 请求参数:apikey
}

猜你喜欢

转载自blog.csdn.net/fangdengfu123/article/details/82621537
今日推荐