[英]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.所以基本上我不太确定如何从我的solidity代码中获取我的参数并将它们传递到部署者的部署function中,以便我使用Truffle进行第二次迁移。
This is the constructor of my Solidity code:这是我的 Solidity 代码的构造函数:
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:然后这是我的 javascript 迁移代码:
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
. stakeToken, rewardToken, rewardPerSecond, startTimestamp, bonusEndTimestamp
。 Now you are initalizing the contract, so you have to pass arguments meaning that inital values.现在你正在初始化合约,所以你必须通过 arguments 表示初始值。
So you have to get values of stakeToken, rewardToken, rewardPerSecond, startTimestamp, bonusEndTimestamp
and pass it所以你必须得到
stakeToken, rewardToken, rewardPerSecond, startTimestamp, bonusEndTimestamp
的值并通过它
deployer.deploy(tokenstaking,
"getStakeToken", // stakeToken
"getRewardToken", //rewardToken,
"1", // 1 reward per second
"92389424982",//startTimestamp
"99239323232"//bonusEndTimestamp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.