Contract-Development

我需要一個智能錢包合約(用於測試)

  • October 9, 2020

我目前任務的測試規範需要創建 50 個可以容納 M+ 代幣的智能錢包

因此我需要一個智能錢包合約。請給我一個簡單的智能錢包合約的來源。它至少需要支持 ERC-20 令牌的接收和發送(最好也支持 ERC-1155 令牌)。

pragma solidity ^0.7.0;

contract Wallet {
 address private owner;

 constructor ()
 payable {
   owner = msg.sender;
 }

 receive ()
 external payable {
   // Do nothing
 }

 function execute (address payable _to, uint _value, bytes memory _data)
 public payable returns (bytes memory) {
   require (msg.sender == owner);

   (bool success, bytes memory result) = _to.call {value: _value} (_data);

   require (success, string (result));
   return result;
 }
}
//SPDX-License-Identifier: GPL-3.0-or-later
// A simple smart wallet to be used for testing.
// Based on code from https://github.com/argentlabs/argent-contracts/blob/develop/contracts/wallet/BaseWallet.sol
pragma solidity ^0.7.1;

contract TestSmartWallet
{
   address payable owner;

   constructor(address payable _owner) payable {
       owner = _owner;
   }

   modifier ownerOnly {
       require(msg.sender == owner, "You are not the owner of the smart wallet");
       _;
   }

   function withdraw(uint256 _amount) external ownerOnly {
       msg.sender.transfer(_amount);
   }

   /**
    * @notice Performs a generic transaction.
    * @param _target The address for the transaction.
    * @param _value The value of the transaction.
    * @param _data The data of the transaction.
    */
   function invoke(address _target, uint _value, bytes calldata _data) external ownerOnly returns (bytes memory _result) {
       bool success;
       (success, _result) = _target.call{value: _value}(_data);
       if (!success) {
           // solhint-disable-next-line no-inline-assembly
           assembly {
               returndatacopy(0, 0, returndatasize())
               revert(0, returndatasize())
           }
       }
       // emit Invoked(msg.sender, _target, _value, _data);
   }

   receive() external payable {
   }
}

我的程式碼好嗎?

現在我需要關於如何使用 Ethers 呼叫它的建議。

引用自:https://ethereum.stackexchange.com/questions/88207