A plugin that allows hardhat-deploy integration with godwoken network using Polyjuice Provider
The goal of the plugin is to have the ability to take existing Ethereum Hardhat codebase and port it to Nervos Layer 2 network only by adding the plugin into existing codebase. All Hardhat commands and execution of Hardhat scripts used ex. for deployment should work after adding the plugin.
-
because
polyjuice-providerdoesn't support transfer of ethers,deterministicDeploymentis not supported by this plugin now -
make sure that you first import
hardhat-deployin your config. This way the plugin will inject convertion of deploy arguments, so it supports using eth addresses and works well withethers -
the following
gw_get_account_id_by_script_hashError is known to be a random error. If this appears make sure you enabledelayAfterDeployin config.
Error: result from jsonRPC gw_get_account_id_by_script_hash is null or undefined. unable to fetch account id from script hash 0x73d89c5d14c9d71bd9380f98fee2337dc517d19f3e41288ee9f78d25ed3e3aafyou can learn more about that here
npm install @rumblefishdev/hardhat-polyjuice-plugin hardhat-deployImport the plugin in your hardhat.config.js. Make sure that it's imported after hardhat-deploy:
require("hardhat-deploy");
require("@rumblefishdev/hardhat-polyjuice-plugin");Or if you are using TypeScript, in your hardhat.config.ts:
import "hardhat-deploy";
import "@rumblefishdev/hardhat-polyjuice-plugin";This plugin creates no additional tasks.
This plugin extends the HardhatUserConfig's NetworkConfig object with optional fields:
rollupTypeHash,ethAccountLockCodeHash,privateKey
This is an example of how to set it in hardhat.config.ts:
export const config: HardhatUserConfig = {
network: {
godwoken: {
url: string;
godwokenConfig: {
privateKey: string;
rollupTypeHash: string;
ethAccountLockCodeHash: string;
delayAfterDeploy?: boolean | Number;
}
},
},
};You can find ethAccountLockCodeHash, rollupTypeHash and url on localhost:6100, if you're using godwoken-kicker, or https://dev.ckb.tools/.
delayAfterDeploy is an optional field, allowing a delay after deploying each contract. It can help with dealing with gw_get_account_id_by_script_hash Error. Setting it to true will add 10000ms delay after every deploy, but you can also configure a number of ms that you want to wait.
All set! You can run
npx hardhat deploy --network godwokenor
yarn hardhat deploy --network godwokento deploy your contracts.
You can find the tests/smoke-test folder, created to check if an update in godwoken chain or @polyjuice-provider/ethers package breaks the plugin functionality.
- Clone the godwoken-kicker repo, make sure that the path is the same as stated in
test-config.json. You can also see there's a dummy ethereum account provided - jq
- curl
- make
Run
yarn smoke-testIt can take a while, especially if your godwoken is currently not up, it needs to build and run some containers. In that case, you will need to give the script root access (make init in godwoken-kicker requires that). The script will keep the chain running in case you want to try it several times. After you are done, run
yarn clean-upto stop the containers.