In Truffle, How can I "act" as a different msg.sender?

Not sure if I really know how to articulate my question correctly, but when trying to play around with what different roles can/can’t do (certain functions they can/can’t execute unless they have permission)

Once I successfully let instance = await MyContract.deployed() and the contract is deployed… and I want to play around with the function transfer()… bounce around money from account to account --> how do I change which address I’M acting as?

Another example --> Playing around with AccessControl.sol, how do I act as different roles?

What is the specific commandI need to write in the terminal to become a “different” msg.sender…?

Thanks to anyone who is able to follow what I’m asking!!

Hi @William

bounce around money from account to account --> how do I change which address I’M acting as?

If you are using the truffle console, you can specify the sender (msg.sender) as follow:

Consider this Solidity function:

function go (uint _n) public {}


const instance = await Contract.deployed()

await instance.go(10,{from:accounts[0]}); // You are using accounts[0] as sender

await instance.go(5,{from:accounts[1]}); // You are using accounts[1] as sender

Cheers,
Dani

1 Like

perfect, thank you dani!

1 Like