【发布时间】:2022-08-23 11:30:19
【问题描述】:
我正在尝试在多边形孟买测试网上部署可升级的智能合约。我收到此错误
smart-contract/node_modules/@openzeppelin/hardhat-upgrades/dist/index.js:108
compiler.settings ?? (compiler.settings = {});
^
SyntaxError: Unexpected token \'?\'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Object.require.extensions.<computed> [as .js] (/Users/jagdish/workspace/speedrun-simple-nft-example/smart-contract/node_modules/ts-node/src/index.ts:1587:43)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/jagdish/workspace/speedrun-simple-nft-example/smart-contract/hardhat.config.ts:4:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
在尝试运行部署脚本时。
这是我的配置和部署脚本:
hardhart.config.ts
import { task } from \"hardhat/config\";
// import \"@nomiclabs/hardhat-waffle\";
import \'hardhat-watcher\';
import \'@openzeppelin/hardhat-upgrades\';
import \'@nomiclabs/hardhat-ethers\';
import dotenv from \"dotenv\"
dotenv.config()
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task(\"accounts\", \"Prints the list of accounts\", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import(\'hardhat/config\').HardhatUserConfig
*/
module.exports = {
solidity: \"0.8.4\",
watcher: {
compilation: {
tasks: [\'compile\'],
},
node: {
tasks: [\'node\'],
},
},
networks: {
matic: {
url: \"https://polygon-rpc.com/\",
accounts: [process.env.ACCOUNT_PRIVATE_KEY]
},
matic_mumbai: {
url: \"https://rpc-mumbai.maticvigil.com\",
accounts: [process.env.ACCOUNT_PRIVATE_KEY]
}
}
};
部署.ts
import { ethers, upgrades } from \"hardhat\";
async function main() {
const contract = await ethers.getContractFactory(\"YourCollectible\");
console.log(\"Deploying Contract ...\");
const c = await upgrades.deployProxy(contract, { constructorArgs: [\"Your Collectables\", \"YCB\"] })
// const c = await contract.deploy(\"Your Collectable\", \"YCB\");
await c.deployed();
console.log(\"Contract deployed to:\", c.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
包.json
{
\"name\": \"smart-contract\",
\"version\": \"1.0.0\",
\"description\": \"\",
\"main\": \"index.js\",
\"scripts\": {
\"run\": \"hardhat compile\",
\"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"
},
\"keywords\": [],
\"author\": \"\",
\"license\": \"ISC\",
\"devDependencies\": {
\"@nomiclabs/hardhat-ethers\": \"^2.0.6\",
\"@nomiclabs/hardhat-waffle\": \"^2.0.3\",
\"@openzeppelin/hardhat-upgrades\": \"^1.20.0\",
\"@typechain/hardhat\": \"^6.1.2\",
\"chai\": \"^4.3.6\",
\"ethereum-waffle\": \"^3.4.4\",
\"ethers\": \"^5.6.9\",
\"hardhat\": \"^2.9.9\",
\"hardhat-watcher\": \"^2.3.0\",
\"ts-node\": \"^10.8.1\",
\"typescript\": \"^4.7.4\"
},
\"dependencies\": {
\"@openzeppelin/contracts\": \"^4.7.0\",
\"dotenv\": \"^16.0.1\"
}
}
我不确定这是我本地的节点版本问题还是我必须降级 @openzeppelin/hardhat-upgrades 版本(我已经尝试过了)。 节点版本:v12.22.10 任何人都可以帮忙吗
标签: blockchain ethereum smartcontracts hardhat openzeppelin