提问人:Eric B 提问时间:11/17/2023 最后编辑:Eric B 更新时间:11/17/2023 访问量:50
不支持的可寻址值 (argument=“target”) - [email protected] 和 OpenZeppelin 5.0.0
unsupported addressable value (argument="target") - [email protected] and OpenZeppelin 5.0.0
问:
当我使用 OpenZeppelins 智能合约向导构建器创建 OpenZeppelin ERC721 智能合约时,尝试使用安全帽将智能合约部署到本地网络时出现错误。我尝试将所有模块更新到最新版本,但我仍然无法让基本的智能合约正常工作。
错误信息:
C:\Users\ericb\Desktop\vue-project>npx hardhat run scripts/deploy.js --network localhost
Compiled 2 Solidity files successfully (evm target: paris).
TypeError: unsupported addressable value (argument="target", value={ }, code=INVALID_ARGUMENT, version=6.8.1)
at makeError (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\utils\errors.ts:687:21)
at assert (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\utils\errors.ts:715:25)
at assertArgument (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\utils\errors.ts:727:5)
at resolveAddress (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\address\checks.ts:122:19)
at C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\contract\contract.ts:172:60
at ParamType.#walkAsync (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\abi\fragments.ts:777:24)
at ParamType.walkAsync (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\abi\fragments.ts:795:24)
at C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\contract\contract.ts:170:22
at Array.map (<anonymous>)
at resolveArgs (C:\Users\ericb\Desktop\vue-project\node_modules\ethers\src.ts\contract\contract.ts:169:37) {
code: 'INVALID_ARGUMENT',
argument: 'target',
value: {},
shortMessage: 'unsupported addressable value'
}
重现步骤:
- 创建一个 vue 项目。选择所有默认值。
npm create vue@latest
- 在新创建的项目中设置安全帽,并选择所有默认值:
cd vue-project
npm install --save-dev hardhat @openzeppelin/contracts @nomicfoundation/hardhat-toolbox
npx hardhat
- 将 solidity 版本更改为 。
hardhat.config.js
0.8.20
- 从左侧菜单中选择时,将 contracts/Lock.sol 中的代码替换为 OpenZeppelin 合约向导中的代码:
Mintable
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC721, Ownable {
constructor(address initialOwner)
ERC721("MyToken", "MTK")
Ownable(initialOwner)
{}
function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
}
- 将 scripts/deploy.js 替换为:
const hre = require("hardhat");
async function main() {
const lock = await hre.ethers.deployContract("MyToken", []);
await lock.waitForDeployment();
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
- 在一个控制台和另一个控制台中运行。
npx hardhat node
npx hardhat run scripts/deploy.js --network localhost
- 智能合约预计在这一点上部署,但我收到的是最初提供的错误消息。
如何解决此问题?或者至少,我如何更好地理解这个错误的根源?似乎它甚至不是来自我编写的任何代码。例如;我没有在我能看到的任何地方使用参数目标,那么我如何理解这个错误消息?
npm 安装以下版本:
+-- @nomicfoundation/[email protected]
+-- @openzeppelin/[email protected]
+-- @vitejs/p[email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
感谢您抽出宝贵时间阅读本文。
答: 暂无答案
评论