首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从转帐到钱包地址的回复错误

从转帐到钱包地址的回复错误
EN

Ethereum用户
提问于 2020-01-24 06:19:35
回答 1查看 41关注 0票数 0

I是计算以太价值的令牌价格和数量的代币,而不是发送计算的乙醚值到卖方帐户,但我得到了在escrow.originatorAddress.transfer(数量)的混合的回复错误;这一行。我也有足够的余额。我在哪里犯了一个错误,下面是我的代码。

代码语言:javascript
复制
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);

}
EN

回答 1

Ethereum用户

回答已采纳

发布于 2020-01-24 07:01:12

escrow.originatorAddress.transfer(amount)语句可以基于以下任何一种原因进行还原:

  1. address(this).balance < amount
  2. escrow.originatorAddress是没有payable回退函数的契约的地址。
  3. escrow.originatorAddress是带有payable回退函数的契约的地址,当您执行上面的语句时该函数会恢复。

请注意,require(address(msg.sender).balance >= amount)并不排除原因#1,因为当函数执行transfer语句时,以太是从契约(this)传递的,而不是从函数的调用方(msg.sender)传递的。

您可能希望使用require(msg.value >= amount),这意味着当msg.sender调用函数时,D19已经向契约传递了足够数量的以太(随后,契约拥有足够数量的以太来传输)。

出于第三个原因,我们需要看到那个后备函数的代码.

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/79289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档