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: })