I是计算以太价值的令牌价格和数量的代币,而不是发送计算的乙醚值到卖方帐户,但我得到了在escrow.originatorAddress.transfer(数量)的混合的回复错误;这一行。我也有足够的余额。我在哪里犯了一个错误,下面是我的代码。
function buyToken(uint256 _tradeId, address token, uint256 _quantity, uint256 _tokenPrice) payable external {
uint256 decimals = 10 ** 9;
//uint256 quantity = _quantity * (10 ** ERC20Interface(token).decimals();
uint256 amount = _quantity.mul(_tokenPrice);
amount = amount.div(decimals);
// amount = amount.div(_quantity);
Escrow storage escrow = escrows[_tradeId];
require (_tradeId == escrow.tradeId, "Trade not found");
require (msg.sender != escrow.originatorAddress, "You are the owner of this sell.");
require(address(msg.sender).balance >= amount, "Insufficient balance");
// require (escrow.receivedQty > 0, "in Sufficent");
escrow.originatorAddress.transfer(amount);
releaseToken(_tradeId, token, escrow, _quantity);
}发布于 2020-01-24 07:01:12
escrow.originatorAddress.transfer(amount)语句可以基于以下任何一种原因进行还原:
address(this).balance < amountescrow.originatorAddress是没有payable回退函数的契约的地址。escrow.originatorAddress是带有payable回退函数的契约的地址,当您执行上面的语句时该函数会恢复。请注意,require(address(msg.sender).balance >= amount)并不排除原因#1,因为当函数执行transfer语句时,以太是从契约(this)传递的,而不是从函数的调用方(msg.sender)传递的。
您可能希望使用require(msg.value >= amount),这意味着当msg.sender调用函数时,D19已经向契约传递了足够数量的以太(随后,契约拥有足够数量的以太来传输)。
出于第三个原因,我们需要看到那个后备函数的代码.
https://ethereum.stackexchange.com/questions/79289
复制相似问题