无法使用 Truffle 部署 ERC20 代币

问题描述

我想使用 Truffle 将遵循“StandardERC20”令牌部署到 kovan 测试网络。 我想部署相同的合同 “https://etherscan.io/address/0x69d9905b2e5f6f5433212b7f3c954433f23c1572#code”给 kovan。 但是我遇到了跟​​随错误。 我添加错误日志和部署此令牌所需的一些文件。 我发现错误在“ServiceReceiver(receiver).pay{value: msg.value}(serviceName);” ServicePayer.sol。 2_deploy_token.js中deploy函数的最后一个地址参数是我的钱包地址。这是对的吗? 我尝试使用混音。但我无法部署它。 我可以为这个错误做什么? 大家帮帮我! -错误日志-

D:\work\Project\alone\monkey-coin>npx truffle migrate --network kovan

Compiling your contracts...
===========================
> Compiling .\contracts\ServicePayer.sol
> Compiling .\contracts\ServiceReceiver.sol
> Compiling .\contracts\TokenRecover.sol
> Artifacts written to D:\work\ph\Project\alone\monkey-coin\build\contracts
> Compiled successfully using:
   - solc: 0.7.0+commit.9e61f92b.Emscripten.clang



Starting migrations...
======================
> Network name:    'kovan'
> Network id:      42
> Block gas limit: 12500000 (0xbebc20)


2_deploy_token.js
=================

   deploying 'StandardERC20'
   -------------------------
   > transaction hash:    0x3628fb04e7566dd9619e790e3e0f0dc4aa31c4c59c31a4acdcddadeae11418ac

Error:  *** Deployment Failed ***

"StandardERC20" -- Cannot create instance of StandardERC20; no code at address 0x210f50C6ED1251606Cb8EfE2D191788d141bF935.

-migration/2_deploy_token.js

const StandardERC20 = artifacts.require("StandardERC20");

module.exports = function(deployer) {
  deployer.deploy(StandardERC20,'Happy Bear','HBT',18,1000000000,'0x4d1c919d233E5c35a9A5a12e82f7D5b12D071997');
};

-contracts/ServiceReceiver.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

//import "eth-token-recover/contracts/TokenRecover.sol";
import "./TokenRecover.sol";
/**
 * @title ServiceReceiver
 * @dev Implementation of the ServiceReceiver
 */
contract ServiceReceiver is TokenRecover {

    mapping (bytes32 => uint256) private _prices;

    event Created(string serviceName,address indexed serviceAddress);

    function pay(string memory serviceName) public payable {
        require(msg.value == _prices[_toBytes32(serviceName)],"ServiceReceiver: incorrect price");

        emit Created(serviceName,_msgSender());
    }

    function getPrice(string memory serviceName) public view returns (uint256) {
        return _prices[_toBytes32(serviceName)];
    }

    function setPrice(string memory serviceName,uint256 amount) public onlyOwner {
        _prices[_toBytes32(serviceName)] = amount;
    }

    function withdraw(uint256 amount) public onlyOwner {
        payable(owner()).transfer(amount);
    }

    function _toBytes32(string memory serviceName) private pure returns (bytes32) {
        return keccak256(abi.encode(serviceName));
    }
}

-contracts/ServicePayer.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

import "./ServiceReceiver.sol";

/**
 * @title ServicePayer
 * @dev Implementation of the ServicePayer
 */
contract ServicePayer {

    constructor (address payable receiver,string memory serviceName) payable {
        ServiceReceiver(receiver).pay{value: msg.value}(serviceName);
    }
}

-contracts/TokenRecover.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title TokenRecover
 * @author Vittorio Minacori (https://github.com/vittominacori)
 * @dev Allow to recover any ERC20 sent into the contract for error
 */
contract TokenRecover is Ownable {

    /**
     * @dev Remember that only owner can call so be careful when use on contracts generated from other contracts.
     * @param tokenAddress The token contract address
     * @param tokenAmount Number of tokens to be sent
     */
    function recoverERC20(address tokenAddress,uint256 tokenAmount) public onlyOwner {
        IERC20(tokenAddress).transfer(owner(),tokenAmount);
    }
}

-contracts/StandardERC20.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;


import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./ServicePayer.sol";
/**
 * @title StandardERC20
 * @dev Implementation of the StandardERC20
 */
contract StandardERC20 is ERC20,ServicePayer {

    constructor (
        string memory name,string memory symbol,uint8 decimals,uint256 initialBalance,address payable feeReceiver
    ) ERC20(name,symbol) ServicePayer(feeReceiver,"StandardERC20") payable {
        require(initialBalance > 0,"StandardERC20: supply cannot be zero");

        _setupDecimals(decimals);

        _mint(_msgSender(),initialBalance);
    }
}

-package.json

{
  "name": "monkey-coin","version": "1.0.0","description": "","main": "index.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },"keywords": [],"author": "","license": "ISC","dependencies": {
    "@openzeppelin/contracts": "^3.3.0-solc-0.7","truffle": "^5.1.60"
  },"devDependencies": {
    "@truffle/hdwallet-provider": "^1.2.1","dotenv": "^8.2.0"
  }
}

我确实想部署这个令牌。 帮帮我!!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)