I'm writing in Solidity using testrpc and truffle.

I wish to test my functions by altering my current address imitate other addresses.

This is what I have tried so far:

function getCurrAddress() constant returns(address currAddr){
    currAddr = msg.sender;
    return currAddr;

var accounts = web3.eth.accounts
contract.getCurrAddress() results in  = '0x53a1962e8844b2c9f1eed6e85e4d2026126ade0e'

web3.eth.defaultAccount = accounts[1]
      == '0xab6fa1d299e3b7d67fffd0829341534684d46560'

contract.getCurrAddress() results in  = '0x53a1962e8844b2c9f1eed6e85e4d2026126ade0e'

Is there a way I can change my current address as defaultAccount doesn't seem to be doing the job?

1 Answer 1


You can just put your preferred address in the from field of the call.


  • Thanks Tjaden Hess! I had actually just read another question about this and it said from:"..." but i didn't know you could specify it in a method. Thanks again.
    – Connor
    Jan 25, 2017 at 21:06
  • 2
    To call a method that requires parameters: contract.function.call(parameters,{from:'myAddress'})
    – Connor
    Jan 25, 2017 at 21:24

Your Answer

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

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