web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.23k stars 4.93k forks source link

1.0.0-beta.46 send transaction, when confirmed throw exception: `TypeError: Cannot read property 'anonymous' of undefined` #2365

Closed BigMurry closed 5 years ago

BigMurry commented 5 years ago

Expected behavior

send transaction should work fine.

Actual behavior

Uncaught (in promise) TypeError: Cannot read property 'anonymous' of undefined
    at AllEventsLogDecoder.decode (web3-eth-contract.umd.js:232)
    at AllEventsLogDecoder.decode (web3-eth-contract.umd.js:263)
    at web3-eth-contract.umd.js:627
    at Array.forEach (<anonymous>)
    at SendContractMethod.afterExecution (web3-eth-contract.umd.js:626)
    at TransactionConfirmationWorkflow.handleSuccessState (web3-core-method.umd.js:103)
    at web3-core-method.umd.js:57

Steps to reproduce the behavior

const Web3 = require('web3');
const abi = [...];
const addr = '0x....';
const web3 = new Web3(window.web3.currentProvider);
const contractInstance = new web3.eth.Contract(abi, addr);
const methodArgs = [...];
contractInstance.methods.myMethod(...methodArgs).send({from, value}, (err, txHash) => {
  console.log(txHash);
});

when transaction is confirmed on the blockchain, exception occurred.

Error Logs

Uncaught (in promise) TypeError: Cannot read property 'anonymous' of undefined
    at AllEventsLogDecoder.decode (web3-eth-contract.umd.js:232)
    at AllEventsLogDecoder.decode (web3-eth-contract.umd.js:263)
    at web3-eth-contract.umd.js:627
    at Array.forEach (<anonymous>)
    at SendContractMethod.afterExecution (web3-eth-contract.umd.js:626)
    at TransactionConfirmationWorkflow.handleSuccessState (web3-core-method.umd.js:103)
    at web3-core-method.umd.js:57

code snapshot:

wechatimg168

Versions

Web3.js - 1.0.0-beta.46 Nodejs - v10.14.0 NPM - v6.4.1

nivida commented 5 years ago

Tested it with:

var Web3 = require('../../web3.js/packages/web3/dist/web3.umd.js');
var abi = require('../tokenContractAbi');
var web3 = new Web3(window.web3.currentProvider);

console.log('Version: ', web3.version);

var contract = new web3.eth.Contract(abi, '0x0ff095b6b4d215d91b4c1d7fce025a9d72afff22');

contract.methods.transfer('0x24BBE93E1D5b43233D921C9c73E15e8576bD7Be1', 1000)
  .send({from: '0x9CC9a2c777605Af16872E0997b3Aeb91d96D5D8c'})
  .then(function (receipt) {
    console.log(receipt);
  }).catch(function (error) {
    console.log(error);
  });

and got the following response:

screenshot 2019-02-10 at 12 05 51

Could you reference a gist file or repository here with the contract and your code example?

BigMurry commented 5 years ago

@nivida when I create the contractInstance, some events' abi is missing from the contractAbi, cause the events came from the other contract.

const contractAbi = [...];
const addr = '0x....';
const contractInstance = new web3.eth.Contract(contractAbi, addr);

Then when transaction is confirmed, it will trigger these methods:

TransactionConfirmationWorkflow -> handleSuccessState -> method.afterExecution -> allEventsLogDecoder.decode

But some events' abi can not found, so that the abiItemModel will be undefined.

I think I found the guilty lines: https://github.com/ethereum/web3.js/blob/35ebbcacbecc75a6cac033fc648d0091e0235a83/packages/web3-eth-contract/src/decoders/AllEventsLogDecoder.js#L45-L47

if the abiModel.getEventBySignature returns undefined, then in the EventLogDecoder.decode method, abiItemModel will be undefined, then line 46 will throw exception.

https://github.com/ethereum/web3.js/blob/35ebbcacbecc75a6cac033fc648d0091e0235a83/packages/web3-eth-contract/src/decoders/EventLogDecoder.js#L43-L48

So in your test, you should make a transaction that can emit an event from other contract.

kim-keepcoding commented 5 years ago

Yeah. I'm got this problem as well. Probably something to do with Escrow contract.

gudcjfdldu commented 5 years ago

I have a similar problem. Is there a way to solve this problem?

gudcjfdldu commented 5 years ago

Yeah. I'm got this problem as well. Probably something to do with Escrow contract.

Do you know what to do with escrow contract? Did you solve this problem?

BigMurry commented 5 years ago

@gudcjfdldu This is a web3 bug, if your transaction will trigger another contract event, web3 will trigger this bug.

I've downgraded to 1.0.0-beta.36.

gudcjfdldu commented 5 years ago

@BigMurry i think Version 1.0.0-beta.37 seems to be the most stable. Currently, web3 works fine in this version.

nivida commented 5 years ago

Thanks all for the additional information. I will fix and release this asap!

kagawagao commented 5 years ago

can release a new version for this bug fix? @nivida