blockchain - ReferenceError:迁移solidity文件时无法在初始化之前访问'TokenFarm'
问题描述
intial_deploy_contract.js 文件
const DappToken = artifacts.require('DappToken.sol')
const DaiToken = artifacts.require('DaiToken.sol')
const TokenFarm = artifacts.require('TokenFarm.sol')
module.exports = async function(deployer, network, accounts) {
//Deploy Mock DAI Token
await deployer.deploy(DaiToken)
const daiToken = await DaiToken.deployed()
//Deploy Dapp Token
await deployer.deploy(DappToken)
const dappToken = await DappToken.deployed()
//Deploy TokenFarm
await deployer.deploy(TokenFarm, dappToken.address, daiToken.address)
const TokenFarm = await TokenFarm.deployed()
//Transfer all tokens to TokenFarm(1 million)
await dappToken.transfer(tokenFarm.address, '1000000000000000000000000')
//Transfer 100 Mock DAI tokens to investor
await daiToken.transfer(accounts[1], '100000000000000000000')
};'
TokenFarm.sol 文件
pragma solidity ^0.5.0;
import "./DappToken.sol";
import "./DaiToken.sol";
contract TokenFarm {
//All code goes here...
string public name = "Dapp Token Farm";
DappToken public dappToken;
DaiToken public daiToken;
constructor(DappToken _dappToken, DaiToken _daiToken) public {
//Storing reference to the DappToken and DaiToken
dappToken = _dappToken;
daiToken = _daiToken;
}
}
该文件成功编译,但是当使用truffle migrate --reset 迁移时,它显示 ReferenceError 为
ReferenceError:在 module.exports (C:\Users\NIHAL SINGH\Desktop\defi_tutorial\migrations\2_deploy_contracts.js:15:25) 在 processTicksAndRejections (internal/process/task_queues.js:93:5) 初始化之前无法访问“TokenFarm” ) 在 Migration._load (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:55:1)
在 Migration.run (C:\Users \NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:171:1)
在 Object.runMigrations (C:\Users\NIHAL SINGH\AppData\Roaming\npm\ node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
在 Object.runFrom (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1) 在 Object.runAll (C:\Users\ NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1) 在 Object.run (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules \truffle\build\webpack:\packages\migrate\index.js:79:1) 在 runMigrations (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\ lib\commands\migrate.js:269:1)
解决方案
您已经在这一行定义了TokenFarm
(大写)T
const TokenFarm = artifacts.require('TokenFarm.sol')
然后你试图在这条线上重新分配它
const TokenFarm = await TokenFarm.deployed()
解决方案:分配给另一个const
名称(例如tokenFarm
- 小写T
),而不是重新分配已经存在的TokenFarm
.
const tokenFarm = await TokenFarm.deployed()
推荐阅读
- php - 为什么这段代码显示 $req 变量未定义?
- scala - 使用相同的方法生成派生特征,但在 Scala 中的每个方法中没有第一个参数
- c - c - 如何将命令行参数重定向到函数?
- php - 从一个 php 函数更新全局值并使其可用于同一类中的另一个函数
- javascript - discord.js ubuntu 未连接到网关
- python - 对 JSON 对象的 SQL 查询
- css - Angular Prime-ng p-tree,如何更改缩进?
- python - 这段代码有问题吗?还是我的电脑?
- kubernetes - 我可以使用容器文件系统并避免使用 Kubernetes 卷吗?
- google-bigquery - BiqQuery GEOGRAPHY 聚类列 - 最大限制为 1024 字节?