2

我是区块链开发的新手,我正在尝试从币安智能链(BSC)获取合约的详细数据,例如(市值、持有人、金额...),并且我正在尝试使用 BSC Scan API(https: //bscscan.com/apis#contracts),我还看到了另一个选项,如比特查询(https://bitquery.io/blog/ethereum-events-api),我应该使用哪个选项,提前谢谢你。

4

1 回答 1

1

官方 API 可用于获取 bscscan.com 验证合约的 ABI 版本。

这是来自浏览器的示例调用:

 https://api.bscscan.com/api
   ?module=contract
   &action=getabi
   &address=0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82
   &apikey=YourApiKeyToken

Javascript 示例:

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider());
var version = web3.version.api;

$.getJSON('https://api.bscscan.com/api?module=contract&action=getabi&address=0x0000000000000000000000000000000000001004&apikey=YourApiKeyToken', function (data) {
    var contractABI = "";
    contractABI = JSON.parse(data.result);
    if (contractABI != '') {
        var MyContract = web3.eth.contract(contractABI);
        var myContractInstance = MyContract.at("0x0000000000000000000000000000000000001004");
        var result = myContractInstance.memberId("0xfe8ad7dd2f564a877cc23feea6c0a9cc2e783715");
        console.log("result1 : " + result);
        var result = myContractInstance.members(1);
        console.log("result2 : " + result);
    } else {
        console.log("Error");
    }
});

来源:https ://docs.bscscan.com/api-endpoints/contracts

于 2021-12-06T22:03:46.220 回答