0

これは、以前に Binance Smart Chain にデプロイしたコントラクトの残高を取得するために実行しているコードです。

let Web3 = require('web3');
const fs = require('fs');

let web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545');

const contractAddress = '0x43045f0Cec750eEb70478B023885d1956588438E';
const contractAbi = JSON.parse(fs.readFileSync("scripts/contract_abi.json").toString())
const contract = new web3.eth.Contract(contractAbi, contractAddress);

contract.methods.balanceOf(contractAddress).call().then(result=>console.log(result)).catch(err => console.log(err));

このコードは私にエラーをスローします:

Error: Returned error: execution reverted
at Object.ErrorResponse (/home/zuber/Projects/HelloBSC/HelloCoin/node_modules/web3-core-helpers/lib/errors.js:28:19)
at /home/zuber/Projects/HelloBSC/HelloCoin/node_modules/web3-core-requestmanager/lib/index.js:303:36
at XMLHttpRequest.request.onreadystatechange (/home/zuber/Projects/HelloBSC/HelloCoin/node_modules/web3-providers-http/lib/index.js:98:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/zuber/Projects/HelloBSC/HelloCoin/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/home/zuber/Projects/HelloBSC/HelloCoin/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/home/zuber/Projects/HelloBSC/HelloCoin/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/home/zuber/Projects/HelloBSC/HelloCoin/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:387:35)
at endReadableNT (internal/streams/readable.js:1317:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
data: null}

コントラクトはhttps://github.com/binance-chain/bsc-genesis-contract/blob/master/contracts/bep20_template/BEP20Token.templateonlyOwnerからコピーペーストされます ( 332 行目に修飾子を追加しただけです)

コントラクトを BSC にデプロイするために使用される Truffle 構成:

const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard BSC port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    testnet: {
      provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s1.binance.org:8545`),
      network_id: 97,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    bsc: {
      provider: () => new HDWalletProvider(mnemonic, `https://bsc-dataseed1.binance.org`),
      network_id: 56,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.5.16", // A version or constraint - Ex. "^0.5.0"
    }
  }
}
4

1 に答える 1