如何使用standard-input-json验证Solidity源码?

使用 Standard-Input-Json(以BSC测试链为例)

使用编译工具获取 Input-Json 的三种方法。

1. Solidity 源码

Storage.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";

contract Storage is Ownable {
    uint256 number;

    function setNumber(uint256 num) public onlyOwner {
        number = num;
    }

    function getNumber() public view returns (uint256) {
        return number;
    }
}

2. JSON格式的输入

Storage.json

{
    "language": "Solidity",
    "sources": {
        "contracts/Storage.sol": {
            "content": "// SPDX-License-Identifier: MIT......"
        },
        "@openzeppelin/contracts/access/Ownable.sol": {
            "content": "// SPDX-License-Identifier: MIT......"
        },
        "@openzeppelin/contracts/utils/Context.sol": {
            "content": "// SPDX-License-Identifier: MIT......"
        }
    },
    "settings": {
        "optimizer": {
            "enabled": true,
            "runs": 200
        },
        "outputSelection": {
            "*": {
                "*": [
                    "abi",
                    "evm.bytecode",
                    "evm.deployedBytecode",
                    "evm.methodIdentifiers",
                    "metadata"
                ],
                "": [
                    "ast"
                ]
            }
        }
    }
}

content内容:将solidity源码转换为JSON字符串。

3.获取 Json

方法1. Hardhat项目下

编译合约:

npx hardhat compile

打开artifacts\build-info路径下的json文件
input字段内容

image.png

方法2. Remix

编译合约后,打开contracts/artifacts/build-info路径下的json文件
input字段内容

image.png

部署合约

remix环境下

image.png
与Storage.json配置文件相同

方法3. Foundry

Storage.sol 再Foundry项目src文件夹下。

执行forge命令:
forge verify-contract --show-standard-json-input 0x0000000000000000000000000000000000000000 src/Storage.sol:Storage

image.png

4.BSC浏览器验证合约

https://testnet.bscscan.com/address/0x1b3104004ebda264b88d04afb6ea66d70a2d51ac#code
1.

image.png
2.

image.png
3.

image.png
4.

image.png

喜欢就点个赞👍哦😄

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值