Не удалось вызвать функцию контракта с его подписью

Документация Web3.js говорит здесь , что методы смарт-контракта доступны через:

  1. Имя: myContract.methods.myMethod
  2. Имя с параметрами: myContract.methods['myMethod(uint256)']
  3. Подпись: myContract.methods['0x58cf5f10']

но когда я вызываю метод со 2-м и 3-м параметром, я не могу получить значение, а показывает много сигнатур объектов.. вот мой код

async function d () {

  var  myContAddr = '0x8175036782E9564C084eD1DA6C44C27150F24316';
  var myContractAbiDefenition = myAbi;
  var myContractInstance = new web3.eth.Contract(myContractAbiDefenition, myContAddr);

  tokens = await myContractInstance.methods['0xc4e41b22'].call();
  //tokens = await myContractInstance.methods['getTotalSupply()'].call(); // its also give same output
  //  tokens = await myContractInstance.methods.getTotalSupply().call(); // this gives me required output "Tokens :  6"  
  console.log("Tokens : ",tokens);
}
d();

вот мой вывод

Tokens :  { call:
   { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
  send:
   { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
  encodeABI: [Function: bound _encodeMethodABI],
  estimateGas: [Function: bound _executeMethod],
  arguments: [],
  _method:
   { constant: true,
     inputs: [],
     name: 'getTotalSupply',
     outputs: [ [Object] ],
     payable: false,
     stateMutability: 'view',
     type: 'function',
     signature: '0xc4e41b22' },
  _parent:
   Contract {
     currentProvider: [Getter/Setter],
     _requestManager:
      RequestManager {
        provider: [HttpProvider],
        providers: [Object],
        subscriptions: {} },
     givenProvider: null,
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider:
      HttpProvider {
        host: 'HTTP://127.0.0.1:7545',
        httpAgent: [Agent],
        withCredentials: false,
        timeout: 0,
        headers: undefined,
        connected: false },
     setProvider: [Function],
     BatchRequest: [Function: bound Batch],
     extend:
      { [Function: ex]
        formatters: [Object],
        utils: [Object],
        Method: [Function: Method] },
     clearSubscriptions: [Function],
     options: { address: [Getter/Setter], jsonInterface: [Getter/Setter] },
     transactionBlockTimeout: 50,
     transactionConfirmationBlocks: 24,
     transactionPollingTimeout: 750,
     defaultChain: undefined,
     defaultHardfork: undefined,
     defaultCommon: undefined,
     defaultAccount: [Getter/Setter],
     defaultBlock: [Getter/Setter],
     methods:
      { balances: [Function: bound _createTxObject],
        '0x27e235e3': [Function: bound _createTxObject],
        'balances(address)': [Function: bound _createTxObject],
        buyToken: [Function: bound _createTxObject],
        '0xa4821719': [Function: bound _createTxObject],
        'buyToken()': [Function: bound _createTxObject],
        getTotalSupply: [Function: bound _createTxObject],
        '0xc4e41b22': [Function: bound _createTxObject],
        'getTotalSupply()': [Function: bound _createTxObject],
        owner: [Function: bound _createTxObject],
        '0x8da5cb5b': [Function: bound _createTxObject],
        'owner()': [Function: bound _createTxObject],
        setTotalSupply: [Function: bound _createTxObject],
        '0xf7ea7a3d': [Function: bound _createTxObject],
        'setTotalSupply(uint256)': [Function: bound _createTxObject],
        totalSupply: [Function: bound _createTxObject],
        '0x18160ddd': [Function: bound _createTxObject],
        'totalSupply()': [Function: bound _createTxObject] },
     events: { allEvents: [Function: bound ] },
     _address: '0x8175036782E9564C084eD1DA6C44C27150F24316',
     _jsonInterface:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] },
  _ethAccounts:
   Accounts {
     currentProvider: [Getter/Setter],
     _requestManager:
      RequestManager {
        provider: [HttpProvider],
        providers: [Object],
        subscriptions: {} },
     givenProvider: null,
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider:
      HttpProvider {
        host: 'HTTP://127.0.0.1:7545',
        httpAgent: [Agent],
        withCredentials: false,
        timeout: 0,
        headers: undefined,
        connected: false },
     setProvider: [Function],
     _ethereumCall:
      { getNetworkId: [Function],
        getChainId: [Function],
        getGasPrice: [Function],
        getTransactionCount: [Function] },
     wallet:
      Wallet {
        _accounts: [Circular],
        length: 0,
        defaultKeyName: 'web3js_wallet' } } }
Ты пропал ()после myContractInstance.methods['0xc4e41b22'].
большое спасибо... да, у меня сработало...
пожалуйста, если у вас есть время, ответьте на мой вопрос, который я разместил ранее ... ethereum.stackexchange.com/questions/77518/…

Ответы (1)

Ты пропал ()после myContractInstance.methods['0xc4e41b22'].