我目前正在实现一个ERC721令牌标记函数契约,但是当我添加传输代码时,会出现一个气体估计错误。
MarineBluesContract(_nftContract).transferFrom(msg.sender, address(this), _tokenId);
function stake(uint256 _tokenId, address _nftContract)
external
nonReentrant
{
require(ntfContractList[_nftContract], "Not allowed NFT contract");
require(msg.sender != address(0), "Invalid staker address");
require(_tokenId != 0, "Invalid token id");
require(MarineBluesContract(_nftContract).ownerOf(_tokenId) == msg.sender, "Not token owner");
// Staking start time
uint48 timestamp = uint48(block.timestamp);
// Staking to contract
MarineBluesContract(_nftContract).transferFrom(msg.sender, address(this), _tokenId);
// Save staking information
stakedTokens.push(
StakedToken(msg.sender, _tokenId, _nftContract, timestamp, false)
);
// Increase in staking count
totalStaked++;
emit Stake(msg.sender, _tokenId, _nftContract, timestamp);
}即使采取上述步骤,也会产生气体估计误差。我不知道为什么,但如果你能猜到或者我做错了什么,请告诉我。提前谢谢!
发布于 2022-11-16 10:07:15
基于require()条件验证_nftContract.ownerOf()没有失败这一事实,我假设您的契约与_nftContract正确地部署在同一个网络上。
transferFrom()可能会因为以下几个原因而失败。最常见的原因可能是:
_tokenId。_tokenId不属于令牌发送方。_tokenId不存在请注意,您正在从契约执行transferFrom()函数-因此,msg.sender (用户执行stake()函数)需要将直接授予yourContract。
https://stackoverflow.com/questions/74455405
复制相似问题