1

https://ethereum.stackexchange.com/posts/3097/edit#=

after this link how to call functions. suppose my contract name is bank and i have deposit fucntion in it. when i am using bank.deposit(1000) it is showing error that bank is undefined. how to solve it?

1

You basically have to use the web3.js library to interact with your contract. If your bank contract has been deployed, then you will have to create a contract instance in web3 to interact with it. Using that instance you can access its functions and call them. So it goes something like this:

var web3 = require("web3");
var fs = require("fs");
var solc = require("solc");

web3 = new web3(new web3.providers.HttpProvider("http://localhost:8545"));
var compiledCode = solc.compile(fs.readFileSync('./bank.sol', 'utf8'),1);
var source = compiledCode.contracts[":array"];
var tokencontract = new  web3.eth.Contract(JSON.parse(source.interface));
tokencontract.deploy({data: source.bytecode}).send({from: UserAddress , gas:1500000}).on('confirmation', function(confirmationNumber, receipt){ console.log(confirmationNumber); tokencontract.options.address = receipt.contractAddress; }).on('receipt', function(receipt){console.log(receipt)})
tokencontract.methods.deposit(100).call().then(console.log)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.