Cannot Read Property sendAsync of Undefined

Hi there,

I am currently working in a NodeJS environment and am trying to run a contract function through web3.

I am currently using version 0.2.3 i think for other dependencies reasons.

This is my code snippit:

async runfunction(abi, addr, functionToRun) {
    const MyContract = new this.web3.eth.contract(abi).at(addr);
    console.log('MyContract', MyContract)
    const txHash = await MyContract.FunctionName('param1','param2')//.sendAsync().get();
    // TRIED THIS : const txHash = await MyContract.FunctionName().sendAsync().get();
    // ALSO THIS const tx = await  MyContract.FunctionName('new string').call().then(function (id) { console.log(id) })
    console.log(txHash);
  }

When I run this however i get the following issue:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘sendAsync’ of undefined
TypeError: Cannot read property ‘sendAsync’ of undefined

When I console.log MyContract i get the following :

Any help would be greatly appriciated.

Thanks
Chadizzle

1 Like

Hey @chadizzle, hope you are ok.

Apparently this is an issue with the web3 version that you are using, can be easily fix by updating your web3 version on nodeJs.

Version 0.20.x got his last maintenance release with v0.20.7. Please update your code to the latest 1.0 version of Web3.js. Further details about the current project state are explained in the release announcement of version 1.0.0-beta.38.

Also I noticed that you have ask the same in stackoverflow and apparently could get the same solution, let us know :face_with_monocle:

Carlos Z

2 Likes

Hey man,

Thanks for the response.

I did try and update and the issue i got is
image

This issue is easily solvable but leads to more and more issues as I solve for others.

and it happens on this line of code

this.web3 = new Web3(wallet.provider)

Thanks again,

Chadizzle