Hi @Homer,
If accounts[1]
is the owner of token 1 (and it exists) then the following should work:
await nft.transferFrom(accounts[1], accounts[0],1,{from: accounts[1]});
You can check the ownerOf
the token before and after.
I recommend trying in a console:
(To setup I used Create an NFT and deploy to a public testnet, using Truffle)
$ mkdir -p build/contracts/
$ cp node_modules/@openzeppelin/contracts/build/contracts/* build/contracts/
$ npx truffle develop
Truffle Develop started at http://127.0.0.1:9545/
Accounts:
(0) 0x0445c33bdce670d57189158b88c0034b579f37ce
(1) 0x46b68a577f95d02d2732cbe93c1809e9ca25b443
...
truffle(develop)> nft = await ERC721PresetMinterPauserAutoId.new("My NFT","NFT", "https://my-json-server.typicode.com/abcoathup/samplenft/tokens/")
undefined
truffle(develop)> nft.mint(accounts[0])
{ tx:
...
truffle(develop)> nft.mint(accounts[0])
{ tx:
...
truffle(develop)> await nft.transferFrom(accounts[0], accounts[1], 1);
{ tx:
...
truffle(develop)> accounts[1]
'0x46B68A577f95d02d2732cbe93c1809E9CA25b443'
truffle(develop)> await nft.ownerOf(1)
'0x46B68A577f95d02d2732cbe93c1809E9CA25b443'
truffle(develop)> await nft.transferFrom(accounts[1], accounts[0],1, {from:accounts[1]});
{ tx:
...
truffle(develop)> accounts[0]
'0x0445c33BdCe670D57189158b88c0034B579f37cE'
truffle(develop)> await nft.ownerOf(1)
'0x0445c33BdCe670D57189158b88c0034B579f37cE'