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

hardhat-deploy plugin #433

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
sample
sample_hardhat-deploy
lib
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ env
# Config files
deployment-config.*.js
!deployment-config.template.js

# OS files
.DS_Store
Thumbs.db
229 changes: 229 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.2.1",
"fs-extra": "^11.2.0",
"hardhat-deploy": "^0.12.4",
"husky": "^9.1.4",
"lint-staged": "^15.2.8",
"prettier": "^3.3.3",
Expand Down
1 change: 1 addition & 0 deletions sample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sample_hardhat-deploy/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.10.0
40 changes: 40 additions & 0 deletions sample_hardhat-deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Testing `hardhat-multibaas-plugin` with `hardhat-deploy`-generated deployment files

## Requirements

This sample project assumes that you already have a MultiBaas deployment setup and a MultiBaas API key provisioned with suitable permissions. The following items will need to be configured.

- Environment variables:

| Variable | Description |
| -------------------- | ---------------------------------------------------- |
| `MB_PLUGIN_API_KEY` | MultiBaas API key with Administrator permissions |
| `MB_PLUGIN_MNEMONIC` | Private key mnemonic to use with Hardhat for testing |

- `hardhat.config.ts` values:

| Entity | `/sample` Value | Description |
| ------------------------------------------------ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HardhatUserConfig.networks.development.url` | `http://localhost:8080/web3/${apiKey}` | If using the Curvegrid Test Network, the host part of the URL should match your deployment. If using a 3rd party web3 provider (Infura, etc.), replace the entire URL. |
| `HardhatUserConfig.networks.development.chainId` | 25846 | 2017072401 for Curvegrid Test Network, otherwise the appropriate Chain ID for your blockchain |

URL `http://localhost:8080` will need to be replaced with your particular MultiBaas deployment URL, and your Web3 API key will need to be stored in the `MB_PLUGIN_API_KEY` environment variable.

By default, a [HD Wallet](https://hardhat.org/config/#hd-wallet-config) is used by `Hardhat` to generate multiple accounts in the network. To deploy smart contracts, please make sure that those accounts are pre-funded or your `MultiBaas` deployment is running on a blockchain network with `gasPrice=0`. If you don't want to use a HD Wallet, you can specify the `accounts` field in `hardhat.config.ts` to be a list of local accounts (an array of hex-encoded private keys) instead.

For further details or to change the default setup, please refer to the sample configuration file [`hardhat.config.ts`](./hardhat.config.ts).

## Testing/Deploying smart contracts

To run tests in this sample project, first go the parent root project to build the `hardhat-multibaas-plugin` by running

```shell
cd ..
npm install && npm run build
```

After that, go to the `sample` folder, then run `npm install` to install dependencies.

The reason we use `npm` for the sample project is it allows us to use the peer dependencies of `@nomicfoundation/hardhat-toolbox` without having to explicitly add them to the `package.json`.

You can run either `npm run test` to test the project using tests defined in `tests` folder or `npm run deploy:` to execute the target script to deploy a smart contract defined in the [contract folder](./contracts) to MultiBaas. At least two accounts are required to successfully complete the tests.
9 changes: 9 additions & 0 deletions sample_hardhat-deploy/contracts/ConvertLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.25;

library ConvertLib{
function convert(uint amount,uint conversionRate) public pure returns (uint convertedAmount)
{
return amount * conversionRate;
}
}
Loading