hardhat:将 NFT 部署到 rinkeby 网络时的问题

Posted

技术标签:

【中文标题】hardhat:将 NFT 部署到 rinkeby 网络时的问题【英文标题】:hardhat : Issues while deploying a NFT to rinkeby network 【发布时间】:2021-11-07 17:52:29 【问题描述】:

我开始了我的第一个区块链教程:

https://www.youtube.com/watch?v=9oERTH9Bkw0&t=696s 回购:https://github.com/PatrickAlphaC/all-on-chain-generated-nft#about-svgs

我正在尝试使用安全帽在 Rinkeby 测试网中部署 NFT。以下是我配置环境的步骤:

已安装安全帽

在我的 .zshrc 中添加以下环境变量(RINKEBY_RPC_URL、PRIVATE_KEY、MAINNET_RPC_URL)

使用 infuria 创建了一个帐户以获取我的 RINKEBY_RPC_URL:'https://rinkeby.infura.io/v3/My_Project_Id'

从我的 Metamask 添加我的 PRIVATE_KEY

在https://www.alchemy.com/ 上创建一个帐户以获取我的 MAINNET_RPC_URL:'https://eth-mainnet.alchemyapi.io/v2/My_Project_Id'

我使用https://faucet.rinkeby.io/ 在我的元掩码(Rinkeby 测试网)上获取以太币。与 LINK 相同

然后当我想使用安全帽部署我的第一个 NFT 时 -> hh deploy --network rinkeby

我有这个错误:

deploying "SVGNFT"An unexpected error occurred:
Error: ERROR processing /Users/macbook/Desktop/all-on-chain-generated-nft/deploy/01_Deploy_SVGNFT.js:
Error: insufficient funds for intrinsic transaction cost (error="name":"ProviderError","code":-32000,"_isProviderError":true, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS, version=providers/5.4.5)
    at Logger.makeError (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at checkError (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:53:16)
    at /Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:215:24
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DeploymentsManager.executeDeployScripts (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1014:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DeploymentsManager.runDeploy (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:849:5)
    at Environment._runTaskDefinition (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
    at SimpleTaskDefinition.action (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat-deploy/src/index.ts:446:32)
    at Environment._runTaskDefinition (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
    at SimpleTaskDefinition.action (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat-deploy/src/index.ts:521:5)
    at Environment._runTaskDefinition (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)

错误信息说:

资金不足以支付内在交易成本

这很奇怪,因为我在 Rinkeby 测试网上添加了一些 Eth 和链接。我错过了什么吗?

编辑 (19/07/21)

我取消了 MNEMONIC 部分的注释,并添加了示例中设置的 gas / gasPrice 变量:

rinkeby: 
        url: RINKEBY_RPC_URL,
        accounts: [PRIVATE_KEY],
        //accounts: 
            //mnemonic: MNEMONIC,
        gas: 2100000,
        gasPrice: 8000000000,
        saveDeployments: true,
    ,

如您所见,它让我更进一步:

Nothing to compile
----------------------------------------------------
reusing "SVGNFT" at 0x7e8d04a7c18f165E9684e887a7978c43f0019a3A
You have deployed an NFT contract to 0x7e8d04a7c18f165E9684e887a7978c43f0019a3A
Verify with:
 npx hardhat verify --network rinkeby 0x7e8d04a7c18f165E9684e887a7978c43f0019a3A
Let's create an NFT now!
We will use ./img/small_enough.svg as our SVG, and this will turn into a tokenURI.
You've made your first NFT!
You can view the tokenURI here data:application/json;base64,eyJuYW1lIjoiU1ZHIE5GVCIsICJkZXNjcmlwdGlvbiI6IkFuIE5GVCBiYXNlZCBvbiBTVkchIiwgImF0dHJpYnV0ZXMiOiIiLCAiaW1hZ2UiOiJkYXRhOmltYWdlL3N2Zyt4bWw7YmFzZTY0LFBITjJaeUI0Yld4dWN6MGlhSFIwY0RvdkwzZDNkeTUzTXk1dmNtY3ZNakF3TUM5emRtY2lJR2hsYVdkb2REMGlOVEF3SWlCM2FXUjBhRDBpTlRBd0lqNEtJQ0E4WTJseVkyeGxJR040UFNJeU5UQWlJR041UFNJeU5UQWlJSEk5SWpJd01DSWdjM1J5YjJ0bFBTSmliR0ZqYXlJZ2MzUnliMnRsTFhkcFpIUm9QU0l6SWlCbWFXeHNQU0ppYkhWbElpQXZQaUFLUEM5emRtYytJQT09In0=
----------------------------------------------------
reusing "RandomSVG" at 0xc71197a95e9cd7e271F1CD08E049720486F62174
You have deployed an NFT contract to 0xc71197a95e9cd7e271F1CD08E049720486F62174
Verify with:
 npx hardhat verify --network rinkeby 0xc71197a95e9cd7e271F1CD08E049720486F62174 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B 0x01be23585060835e02b77ef475b0cc51aa1e0709 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311 100000000000000000
Duplicate definition of Transfer (Transfer(address,address,uint256,bytes), Transfer(address,address,uint256))
Let's create an NFT now!
You've made your NFT! This is number 0x0000000000000000000000000000000000000000000000000000000000000002
Let's wait for the Chainlink VRF node to respond...
Now let's finsih the mint...

然后当调用 Chainlink VRF 节点时,我得到了一个新错误:

Error: ERROR processing /Users/macbook/Desktop/all-on-chain-generated-nft/deploy/02_Deploy_RandomSVG.js:
Error: cannot estimate gas; transaction may fail or may require manual gas limit (error="name":"ProviderError","code":3,"_isProviderError":true,"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003145524337323155524953746f726167653a2055524920717565727920666f72206e6f6e6578697374656e7420746f6b656e000000000000000000000000000000", method="call", transaction="from":"0x76834D0CbE40eDedb2844Afd98896c10DbA6CE92","gasLimit":"type":"BigNumber","hex":"0x111c78","to":"0xc71197a95e9cd7e271F1CD08E049720486F62174","data":"0xc87b56dd0000000000000000000000000000000000000000000000000000000000000000","accessList":null, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.4.5)
    at Logger.makeError (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at checkError (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:80:16)
    at EthersProviderWrapper.<anonymous> (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:555:20)
    at step (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
    at Object.throw (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
    at rejected (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DeploymentsManager.executeDeployScripts (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1014:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at DeploymentsManager.runDeploy (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:849:5)
    at Environment._runTaskDefinition (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/Users/macbook/Desktop/all-on-chain-generated-nft/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)

分配给gas和gasPrice的值有问题吗?

【问题讨论】:

多少 ETH 和 LINK?也许你需要更多 嗨@PatrickCollins。 18,75ETH 和 200 LINK 所以我不认为这是问题所在......顺便谢谢你的内容!这是我的地址:>rinkeby.etherscan.io/address/… 嗯...我以前从未见过这个错误。如果这里没有其他人回应,我会悬赏这个问题,看看我们是否可以多看几眼。 【参考方案1】:

检查hardhat.config.js 中先前定义的网络之一结束后是否缺少逗号。

例如,我试图部署到mainnet,它的正上方是这个定义:

ganache: 
    url: 'http://localhost:8545',
    accounts: [PRIVATE_KEY] // <<<< comma was missing here
    // accounts: 
    //     mnemonic: MNEMONIC,
    // 
,
mainnet: 
    url: MAINNET_RPC_URL,

添加逗号,即:[PRIVATE_KEY], 为我解决了这个问题。

【讨论】:

【参考方案2】:

我按照另一个答案code modified 中的建议评论了助记符,它部分解决了问题。

另外更改 hardhat.config.js 文件的这一部分对我有用:

rinkeby: 
        url: RINKEBY_RPC_URL,
        accounts: [PRIVATE_KEY],
        //accounts: 
            //mnemonic: MNEMONIC,
        gas: 2100000,
        gasPrice: 8000000000,
        saveDeployments: true,
    ,

【讨论】:

它让我更进一步,但我现在有一个新错误,正如我在下面的评论中指定的那样。你能告诉我计量单位是什么(gas/gasPrice)吗?谢谢【参考方案3】:

在您的 hardhat.config.js 文件中,确保正确填写“rinkeby”部分以使用您的 PRIVATE_KEY 环境变量,而不是助记符。即帐户:[PRIVATE_KEY] 应取消注释,而应将 MNEMONIC 注释掉

【讨论】:

以上是关于hardhat:将 NFT 部署到 rinkeby 网络时的问题的主要内容,如果未能解决你的问题,请参考以下文章

在安全帽上部署合约或铸造 NFT 时出现错误:ProviderError: invalid sender

无法将 Solidity 合约部署到 Rinkeby 网络(无效的 asm.js:stdlib 的无效成员)

基于Hardhat编写合约测试用例

Web3与智能合约:开发一个简单的DApp并部署到以太坊测试网(Solidity+Hardhat+React)① 环境搭建

truffle部署到测试网rinkeby

为部署在 RinkeBy 测试网上的智能合约执行 ERC20 代币“传输函数”的原始交易