I have the following function in my ERC721 Smart Contract:
function tokTransfer(address payable from, address to, uint256 tokenId, uint256 price) external payable {
require(msg.value >= price);
this.safeTransferFrom(from, to, tokenId);
AddressUpgradeable.sendValue(from, price);
}
I am calling this function from my front-end Dapp using the following:
this.contInst.methods.tokTransfer(tokOwner, this.account, TokenId, PriceBN).send({
from: this.account, // Corresponds to Purchaser Account
value: this.web3.utils.toWei(PriceStr, 'ether')
})
Token owners have called the setApprovalForAll on my Smart Contract, granting it authorisation to sell their tokens on their behalf. However, I am able to call this function directly in Truffle with the following statement (using the Purchaser account (i.e. accounts[2]) as the _msgSender
):
instance.tokTransfer(accounts[1], accounts[2], 1001, '2500000000', {from: accounts[2], value: '2500000000'})
How can I actually call my function, which itself calls the safeTransferFrom
OpenZeppelin function, while the Sender (_msgSender
) of the Transaction does not satisfy the require
statement in the function below? Am I misinterpreting the _msgSender
value, or non properly understanding something?
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
Thank you. J