0

I created a simple contract and deployed in with testrpc using truffle migrate. In the contract I have a variable

creator = msg.sender;

When calling the contract, it shows that the contract is always called on the first address from the 10 addresses in testrpc.

This is how i call the contract in the truffle console:

var instanceTest MyContract.deployed().then(function(instance) { instanceTest = instance; }) instanceTest.creator.call()

This returns the first address from the list of addresses in the chain. Why is it the first and how do I call the contract on another address?

Thank you.

1

Truffle uses the first the default address so msg.sender would be accounts[0]

To change it use this:

var creatorAddress = accounts[0];
var firstOwnerAddress = accounts[1];
var secondOwnerAddress = accounts[2];
var externalAddress = accounts[3];

So know you have these address that you can use in your code:

To call a function from these addresses just use this:

 var instanceTest
 MyContract.deployed().then(function(instance) { instanceTest = instance; })
 instanceTest.creator.call({from: firstOwnerAddress})

Notice I used from within the curly braces in the call parameter.

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.