How can I test (truffle test or development console) the following:

await nft.transferFrom(accounts[0], accounts[1], 1); 
await nft.transferFrom(accounts[1], accounts[0],1);

The second line throws

ERC721: transfer caller is not owner nor approved

If I change to

await nft.transferFrom(accounts[1], accounts[0],1,{from: accounts[1]});

the following exception is thrown:

Ownable: caller is not the owner

How can I test a transfer from another account then accounts[0]?

1 Answer 1


Truffle supports optional parameters for all calls. You can see them at least here (even if this is for the default parameters, it's valid for any call): https://github.com/trufflesuite/truffle/tree/master/packages/contract#mycontractdefaultsnew_defaults

So you can just an extra parameter from, like this: await nft.transferFrom(accounts[0], accounts[1], 1, { from: accounts[1] });

  • Thank you very much @Lauri for your answer. If I use await nft.transferFrom(accounts[1], accounts[0],1,{from: accounts[1]});I get Ownable: caller is not the owner. Please see in my question above.
    – user66732
    Mar 2, 2021 at 11:59
  • Sorry. Your solution works perfect! Thank you very much, Lauri!
    – user66732
    Mar 3, 2021 at 10:02

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.