7

I have a contract with which 2 accounts should interact.

The accounts are in the same node in web3.eth.accounts.

The contract was created by accounts[0].

How can I call that contract from accounts[1] from web3.js?

1 Answer 1

8

when you call your function you can specify a from parametern in the transactionOptions. Suppose you have a contract instance contract and want to call vote function. Then this calls it from account 1:

let account0;
web3.eth.getAccounts().then(function(result) {
  account0 = result[0];
  contract.vote(2, {
    from: account0
  });
});

You can read more about it here: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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