代码之家  ›  专栏  ›  技术社区  ›  Joey Yi Zhao

为什么我不能在合同中转让以太?

  •  0
  • Joey Yi Zhao  · 技术社区  · 4 年前

    我正在将一个合约部署到以太坊EVM环境中,并使用 Ropsten 测试网络。它将1个以太发送到另一个帐户,该帐户是从方法参与者传递的。

    部署后,我设置了目标帐户的地址 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 何时呼叫 transfer 方法但我看到以下错误:

    transact to Leger.transfer errored: VM error: revert.
        The transaction has been reverted to the initial state.
    Reason provided by the contract: "Transfer failed.".
    Debug the transaction to get more information.
    
    

    我的账户有99个以太币,为什么我会出现以上错误?

    // SPDX-License-Identifier: MIT
    pragma solidity 0.7.4;
    pragma experimental ABIEncoderV2;
    
    contract Leger {
    
        address payable owner;
    
        constructor(){
            owner = msg.sender;
        }
    
        function transfer(address payable _recipient) public payable {
            
            bool success = _recipient.send(1);
            require(success, "Transfer failed.");
        }
    
    
        function getBalance() public view returns (uint256) {
            return owner.balance;
        }
        
    
    }
    
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Shivam Sharma    4 年前

    如果您发送1 ETH,则提供1*10^18,相当于1000000000000000000wei。

    我没有那么多经验,但我认为你必须首先创建一些代币,才能使用ETH在你的网络上进行交换。