I'd like to deploy follow "StandardERC20" token to kovan test net using Truffle. I want to deploy same contract like "https://etherscan.io/address/0x69d9905b2e5f6f5433212b7f3c954433f23c1572#code" to kovan. But I got follow errors. I added error log and some files needed to deploy this token. And I found that error is in "ServiceReceiver(receiver).pay{value: msg.value}(serviceName);" of ServicePayer.sol. last address parameter of deploy function in 2_deploy_token.js is my wallet address. is it correct? And I tried to use remix. But I couldn't deploy it. What Can I do for this error? Help me,everyone! -Error log-
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.
-migaration/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"
}
}
I want to deploy this token surely. Help Me!!!