0

我有一个代理合约,想替换底层的实现合约。

我已经有了智能合约的 abi 和字节码(从 artifacts 文件夹中检索),所以这就是我所做的:

const NFTv2 = await ethers.getContractFactory(upgradedContract.abi, upgradedContract.bytecode);
contract = await upgrades.upgradeProxy(proxyContract.address, NFTv2);

它工作正常,但我不希望合同存在于我的contracts文件夹中,因此我已将其删除并npx hardhat compile再次运行。

现在,当我再次尝试运行此部署脚本时,安全帽不断抛出此错误:

Error: The requested contract was not found. Make sure the source code is available for compilation
      at getContractNameAndRunValidation (node_modules/@openzeppelin/upgrades-core/src/validate/query.ts:46:11)
      at Object.getStorageLayout (node_modules/@openzeppelin/upgrades-core/src/validate/query.ts:54:41)
      at Object.deployImpl (node_modules/@openzeppelin/hardhat-upgrades/src/utils/deploy-impl.ts:30:18)
      at Proxy.upgradeProxy (node_modules/@openzeppelin/hardhat-upgrades/src/upgrade-proxy.ts:36:22)

经过一些尝试错误,似乎与缓存文件夹有关,一旦缓存文件夹中的相关元数据消失,就会弹出此错误,否则不会。

有人可以指导我解决这个问题吗?如何在不将合同留在contracts文件夹中的情况下仅使用 abi 和字节码部署合同?

谢谢!:)

这是我升级合约的代码:

// SPDX-License-Identifier: Apache2.0
pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/presets/ERC1155PresetMinterPauserUpgradeable.sol";

contract Test is ERC1155PresetMinterPauserUpgradeable {
    string private _uri;

    event upgradeEvent(string);

    function uri(uint256) public view virtual override returns (string memory) {
        return string(abi.encodePacked(_uri, "/new"));
    }

    function seturi(string memory uri) public {
        emit upgradeEvent("this is an upgraded contract");
        _uri = uri;
    }
}
4

0 回答 0