I have a contract that is deployed on the local test blockchain. I am using testrpc and truffle for testing my contract. However, I wish to execute functions of the contract from multiple accounts (2 at least). Is it possible using truffle console?

  • By default, it always uses account[0] but can I do the same from different account so that msg.sender value will now have different account address?
    – rakeshgn
    Mar 26 '17 at 12:18

like mentionned in the doc :

var account_one = "0x1234..."; // an address
var account_two = "0xabcd..."; // another address

var meta;

MetaCoin.deployed().then(function(instance) {
  meta = instance;
  return meta.sendCoin(account_two, 10, {from: account_one});
}).then(function(result) {
  // If this callback is called, the transaction was successfully processed.
  alert("Transaction successful!")
}).catch(function(e) {
  // There was an error! Handle it.

just creat two variables each contain an account address and then send differents transactions.

  • Sorry that I forgot to mention here. I did look at the truffle doc and saw this example before your post. Not sure how I missed it. Thanks a lot man!
    – rakeshgn
    Mar 26 '17 at 18:24

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.