我确认批准是准确的,但是在使用erc20函数时,我会收到“还原transferFrom()转移金额超过允许量”的错误。然而,由于某种原因,内部_transfer()函数的工作没有任何问题。
我查过了,transferFrom()是公开的,而不是外部的。
以下代码导致错误:
function addLiquidity(uint256 _tokenAmount) external payable onlyOwner {
// Transfer the tokens from the sender to the contract
// Sender should approve the contract spending the tokens
require(allowance(msg.sender, address(this)) >= _tokenAmount);
transferFrom(msg.sender, address(this), _tokenAmount);
}这样做的地方:
function addLiquidity(uint256 _tokenAmount) external payable onlyOwner {
// Transfer the tokens from the sender to the contract
// Sender should approve the contract spending the tokens
require(allowance(msg.sender, address(this)) >= _tokenAmount);
_transfer(msg.sender, address(this), _tokenAmount);
}注意,在每次尝试传递之前都要注意require语句,因此清楚地显示契约允许传输令牌。
为什么_transfer能工作,而transferFrom却不能工作?transferFrom不应该工作吗,特别是考虑到津贴已经被正确设置了?
发布于 2023-04-03 01:37:07
我真的不认为allowance是一成不变的。因为_transer在任何地方都不需要allowance。你能分享_transferFrom吗?
https://ethereum.stackexchange.com/questions/148409
复制相似问题