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?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communitywhen 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