简体   繁体   中英

Migrate with constructor parameters in Truffle

So basically I'm not quite sure how I can get my parameters from my solidity code and pass them in the deploy function of the deployer for my 2nd migration with Truffle.

This is the constructor of my Solidity code:

constructor(
    IBEP20 _stakeToken,
    IBEP20 _rewardToken,
    uint256 _rewardPerSecond,
    uint256 _startTimestamp,
    uint256 _bonusEndTimestamp
) public {
    stakeToken = _stakeToken;
    rewardToken = _rewardToken;
    rewardPerSecond = _rewardPerSecond;
    startTimestamp = _startTimestamp;
    bonusEndTimestamp = _bonusEndTimestamp;
    // staking pool
    poolInfo.push(PoolInfo({
    lpToken: _stakeToken,
    allocPoint: 1000,
    lastRewardTimestamp: startTimestamp,
    accRewardTokenPerShare: 0
    }));
    totalAllocPoint = 1000;
}

Then this is my javascript migration code:

const tokenstaking = artifacts.require("TokenStaking");
module.exports = function(deployer) {
deployer.deploy(tokenstaking, stakeToken, rewardToken, rewardPerSecond, startTimestamp, 
bonusEndTimestamp);};

Each time I receive the same error for all parameters:

ReferenceError: stakeToken is not defined

How can I reference my parameters? help

for parameters you have to pass values. You defined constructor before with parameters. stakeToken, rewardToken, rewardPerSecond, startTimestamp, bonusEndTimestamp . Now you are initalizing the contract, so you have to pass arguments meaning that inital values.

So you have to get values of stakeToken, rewardToken, rewardPerSecond, startTimestamp, bonusEndTimestamp and pass it

deployer.deploy(tokenstaking, 
   "getStakeToken",  // stakeToken 
   "getRewardToken", //rewardToken, 
   "1", // 1 reward per second
   "92389424982",//startTimestamp 
    "99239323232"//bonusEndTimestamp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM