Skip to content

A tool to test and deploy ethereum smart contract

License

Notifications You must be signed in to change notification settings

wighawag/rocketh

Repository files navigation

rocketh

The deployer tool for ethereum smart contract

migration from hardhat-deploy v1

hardhat-deploy v2 now uses rocketh, (a modular system to handle deployment) under the hood and use a similar mechanism as hardhat-deploy v1 to deploy contracts. But the api is different.

Fun fact: hardhat-deploy started as "rocketh" in 2018 before it became a plugin for hardhat (called buidler back then).

In hardhat-deploy v1 the scripts where exported functions with optional fields (tags, dependencies, skip, etc...)

In V2 the scripts are also functions but hey are created by calling the execute function from rocketh

In v2 we do this:

import {execute} from 'rocketh';
import '@rocketh/deploy';
import {context} from './_context.js';

export default execute(
	context,
	async ({deploy, namedAccounts, artifacts}) => {
		const {deployer} = namedAccounts;

		await deploy('GreetingsRegistry', {
			account: deployer,
			artifact: artifacts.GreetingsRegistry,
			args: [''],
		});
	},
	{tags: ['GreetingsRegistry', 'GreetingsRegistry_deploy']}
);

in hardhat-deploy v1 we did that instead:

import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DeployFunction} from 'hardhat-deploy/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
	const {deployer} = await hre.getNamedAccounts();
	const {deploy} = hre.deployments;

	// proxy only in non-live network (localhost and hardhat network) enabling HCR (Hot Contract Replacement)
	// in live network, proxy is disabled and constructor is invoked
	await deploy('GreetingsRegistry', {
		from: deployer,
		args: [''],
	});
};
export default func;
func.id = 'deploy_greetings_registry'; // id required to prevent reexecution
func.tags = ['GreetingsRegistry'];

Few notes:

Notice the following import:

import '@rocketh/deploy';

rocketh core library is very simple and it does not even know how to deploy contract, just to save deployment information, read it and managed them.

@rocketh/deploy is a rocketh plugin that adds the deploy function.

Also notice this import:

import {context} from './_context.js';

It import what we call the context, you can name the file any way you want or import it differently depending on the script. We like to call it _context and be shared by any script that want to use the same context as all other scripts.

Here is the content of this file:

import artifacts from '../generated/artifacts.js';
import '@rocketh/signer';

export const context = {
	accounts: {
		deployer: {
			default: 0,
		},
	},
	artifacts,
} as const;

Notice how the named-accounts are now configured there instead of inside the hardhat.config.js file.

The benefit is type safety.

We also pass in the artifacts that are in this case generated by the hardhat-deploy v2 plugin automatially for you.

what is missing so far from hardhat-deploy v1 ?

  • diamond support diamond support would be implementable via a plugin, like @rocketh/deploy but none exist at the moment