1

I read all the documentation, but this simple example that tries to invoke function doesn't work.

The initiation:

var contractAbi = web3.eth.contract(myABI);

var myContract = contractAbi.at(myAddress);

seems to be okay. But:

myContract.methods.dummy().call({from: web3.eth.accounts[0],data:getData}, function(error, result){ if(!error) { console.log(JSON.stringify(result)); console.log(result); } else console.error(error); });

raise the following exception:

myContract.methods is undefined

while the following code:

var getData = myContract.dummy.getData() web3.eth.sendTransaction({to:myAddress, from:web3.eth.accounts[0],data:getData, gas:30000 },function(error, result){ if(!error) { console.log(JSON.stringify(result)); console.log(result); } else console.error(error); });

Pops a metamask transaction creation pop-up, and the return value is not my function "dummy" value.

Thanks for the help.

More information:

I includes :

< script language="javascript" type="text/javascript" src="web3.min.js">

and also the following standart code:

window.addEventListener('load', function() { // Checking if Web3 has been injected by the browser (Mist/MetaMask) if (typeof web3 !== 'undefined') { // Use Mist/MetaMask's provider web3js = new Web3(web3.currentProvider); startApp() } else { console.error("Please use a web3 browser"); // Handle the case where the user doesn't have Metamask installed // Probably show them a message prompting them to install Metamask } // Now you can start your app & access web3 freely: })

2

1 Answer 1

1

With version 1.0 of web3, contract is now Contract (note the capital C).

Change this:

web3.eth.contract(myABI); 

to this:

web3.eth.Contract(myABI); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.