首页 > 其他分享 >如何把文件上传IPFS以及如何开放合约源代码

如何把文件上传IPFS以及如何开放合约源代码

时间:2022-11-23 22:12:28浏览次数:60  
标签:IPFS verify etherscan goerli https hardhat 源代码 上传

IPFS存文件

1、去中心化存储NFT的元数据
用这个网站https://www.pinata.cloud/ ,用来IPFS PIN files,笔者传了一个文件得到CID:
QmYgceyozYeZkeN5v1ZcS5rdpLxqWXrcLDCevT1FZyufaa

2、如何查看图片文件:
https://cloudflare-ipfs.com/ipfs/QmYgceyozYeZkeN5v1ZcS5rdpLxqWXrcLDCevT1FZyufaa
Cloudflare's IPFS gateway provides a read-only, HTTP-accessible interface to the Interplanetary File System (IPFS).
或者ipfs://QmYgceyozYeZkeN5v1ZcS5rdpLxqWXrcLDCevT1FZyufaa 这个可以在Brave浏览器直接打开,因为内置了IPFS节点。

如何开放合约源码

1、先去etherscan申请api key:
https://etherscan.io/login.aspx
2、当然可以直接在etherscan上按照提示一步步的进行verify and publish,然后填入合约源代码。这里使用另一种方式,用Hardhat:
申请etherscan的api key,然后在hardhat工程里:

npm i -D @nomiclabs/hardhat-etherscan

hardhat.config.js文件里添加:

require("@nomiclabs/hardhat-etherscan");

// Rest of code
...

module.exports = {
  solidity: "0.8.17",

  // Rest of the config
  ...,
  etherscan: {
    // Your API key for Etherscan
    // Obtain one at https://etherscan.io/
    apiKey: "",
  }
};

执行verify

npx hardhat verify 0xd1f21ba617b622e290cd3c5d2a10193177c269fa --network goerli 

报timeout,因为终端没有像浏览器一样走proxy,ClashX没法实现这个功能,下载安装ClashX Pro, 由于是基于前者的,所以安装之后配置自动就导入了不用重新配置。
ping api-goerli.etherscan.io 可以ping通了,重新执行verify:

$ npx hardhat verify 0xd1f21ba617b622e290cd3c5d2a10193177c269fa --network goerli

Nothing to compile

Successfully submitted source code for contract

contracts/MyEpicNFT.sol:MyEpicNFT at 0xd1f21ba617b622e290cd3c5d2a10193177c269fa

for verification on the block explorer. Waiting for verification result...

 

Successfully verified contract MyEpicNFT on Etherscan.

https://goerli.etherscan.io/address/0xd1f21ba617b622e290cd3c5d2a10193177c269fa#code

参考:

https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/2247

https://heaid.top/index.php/archives/34/

标签:IPFS,verify,etherscan,goerli,https,hardhat,源代码,上传
From: https://www.cnblogs.com/lyhero11/p/16920325.html

相关文章