Call contract from another account using web3.js

by Henrique Barcelos   Last Updated October 09, 2019 15:28 PM - source

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?

Answers 1

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];, {
    from: account0

You can read more about it here:

March 30, 2016 19:18 PM

Related Questions

Contract changing another contract's state

Updated August 04, 2017 14:28 PM

Web3 Function Calls are very slow !

Updated July 31, 2017 15:28 PM

Estimating gas cost of function with multiple inputs

Updated August 18, 2017 14:28 PM

Sending ether via Contract instance

Updated July 10, 2018 19:28 PM