Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: include Hardhat project example #176

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ You can use the following checklist to make sure the new release, either integra
- [ ] **Check `servers` list.** Make sure _Servers_ listed in <https://server-verify.hashscan.io/api-docs/> are properly set to Hedera and local servers.
- [ ] **Verify a contract using Hashscan.** Deploy a contract with your favorite tool. Verify it using the `VERIFY CONTRACT` button in the _Contract_ view in Hashscan. Make sure the verified contract is visible from the `repository`. See [How to Verify a Smart Contract on HashScan](https://docs.hedera.com/hedera/tutorials/smart-contracts/how-to-verify-a-smart-contract-on-hashscan) for more details.
- [ ] **Verify a contract using the Verifier UI**. Deploy a contract with your favorite tool. Verify it using the Verifier UI. Make sure the verified contract is visible from the `repository`. Make sure the verified contract is visible as such in the _Contract_ view in Hashscan.
- [ ] **Ensure your deployed contracts are listed.**. Use the endpoint <https://server-verify.hashscan.io/files/contracts/296> (change the domain if necessary) and make sure the deployed contracts are listed here.
- [ ] **Verify a contract using a Hardhat project**. Make sure the [`hardhat-verify`](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify) plugin is able to verify a contract in the deployed instance. See [tools/README](./tools/README.md) for more details.
- [ ] **Ensure your deployed contracts are listed.** Use the endpoint <https://server-verify.hashscan.io/files/contracts/296> (change the domain if necessary) and make sure the deployed contracts are listed there.

Once you ensure the new release works properly, create a GitHub Release to let users and developers of what has changed.
Go to <https://github.com/hashgraph/hedera-sourcify/releases> and follow the steps under _Draft a new release_.
Expand Down
9 changes: 7 additions & 2 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ forge create --rpc-url http://localhost:7546 \

You can also verify contracts using Hardhat with the [`hardhat-verify`](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify) plugin using our verification service.

> There is currently a minor issue that might confuse users but that does not affect Sourcify verification <https://github.com/NomicFoundation/hardhat/issues/4776>.
> [!NOTE]
> There is a minor issue that might confuse users but that does not affect Sourcify verification.
> See <https://github.com/NomicFoundation/hardhat/issues/4776> for more details.

Create a new Hardhat project, install its dependencies and use the following `hardhat.config.js`

> [!TIP]
> You can use the [Hardhat starter project](./hardhat/) to work with a custom Sourcify instance.

```js
require("@nomicfoundation/hardhat-toolbox");

Expand All @@ -82,7 +87,7 @@ module.exports = {
};
```

> [!NOTE]
> [!IMPORTANT]
> Both `apiUrl` and `browserUrl` expect an URL without a trailing slash.
> Having a trailing slash in the Sourcify URLs may cause unexpected errors.

Expand Down
18 changes: 18 additions & 0 deletions tools/hardhat/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Setup your accounts for different networks
TESTNET_PK=
PREVIEWNET_PK=
LOCALNET_PK=

# Select the Sourcify instance you want to target

# Production Hedera Sourcify instance
SOURCIFY_API_URL=https://server-verify.hashscan.io
SOURCIFY_BROWSER_URL=https://repository-verify.hashscan.io

# Staging Hedera Sourcify instance
# SOURCIFY_API_URL=https://server-sourcify.hedera-devops.com
# SOURCIFY_BROWSER_URL=https://repository-sourcify.hedera-devops.com

# Local Hedera Sourcify instance
# SOURCIFY_API_URL=http://localhost:5555
# SOURCIFY_BROWSER_URL=http://localhost:10000
6 changes: 6 additions & 0 deletions tools/hardhat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules/
/.env

# Hardhat output files
/cache/
/artifacts/
22 changes: 22 additions & 0 deletions tools/hardhat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Sample Hardhat Project

> [!IMPORTANT]
> Create a `.env` file
>
> ```sh
> cp .env.template .env
> ```
>
> and setup your accounts for different networks, and select the Sourcify instance you want to target.

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.js
```
34 changes: 34 additions & 0 deletions tools/hardhat/contracts/Lock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
43 changes: 43 additions & 0 deletions tools/hardhat/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

const accounts = pk => pk ? [pk] : undefined;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.19",

defaultNetwork: "testnet",

networks: {
testnet: {
url: 'https://testnet.hashio.io/api',
accounts: accounts(process.env.TESTNET_PK),
chainId: 296,
},
previewnet: {
url: 'https://previewnet.hashio.io/api',
accounts: accounts(process.env.PREVIEWNET_PK),
chainId: 297,
},
localnet: {
url: 'http://localhost:7546',
accounts: accounts(process.env.LOCALNET_PK),
chainId: 298,
},
},

etherscan: {
enabled: false,
},

sourcify: {
// Disabled by default
// Doesn't need an API key
enabled: true,
// Optional: specify a different Sourcify server
apiUrl: process.env.SOURCIFY_API_URL,
// Optional: specify a different Sourcify repository
browserUrl: process.env.SOURCIFY_BROWSER_URL,
}
};
Loading
Loading