locklift-deploy-artifacts
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Logo

Deploy artifacts plugin

Locklift plugin that enables you to store build artifacts across contract migration scripts.

Installation

  1. Install plugin.
npm i --save-dev locklift-deploy-artifacts
  1. Initialize the plugin via the locklift.config.ts file.
// locklift.config.ts
// ...
import { FactorySource } from "./build/factorySource";
import { DeployArtifactsExtension } from "locklift-deploy-artifacts";
import "locklift-deploy-artifacts";

declare module "locklift" {
  export interface Locklift<FactorySource> extends DeployArtifactsExtension<FactorySource> {}
}
// ...

Usage

The deploy artifacts plugin provides methods to interact with the build artifacts.

deployContract()

This method deploys a contract and saves its artifacts to the ./artifacts directory.

It takes arguments:

  • alias - the alias of the contract
  • version - the version of the contract, use "latest" to increment version
  • args - the deployment parameters, the same as you use at locklift.factory.deployContract()
  • deployFn - the function to deploy contract, default value locklift.factory.deployContract
const { contract, tx } = await locklift.deployArtifacts.deployContract(alias, version, args);

getArtifacts()

This method returns an object with the current state of the build artifacts:

// scripts/get_deploy_artifacts.ts
import { IDeployArtifacts } from "../artifacts/artifacts";
const artifacts = locklift.deployArtifacts.getArtifacts<IDeployArtifacts>();
console.log("SampleA contract address", artifacts.local.SampleA.v0.address)

read deploy artifacts

reset()

This method deletes all artifacts and resets storage:

locklift.deployArtifacts.reset();

getContract()

This method returns the instance of the deployed contract.

// scripts/get_deployed_contract.ts
import { IDeployArtifacts } from "../artifacts/artifacts";

async function main() {
  const artifacts = locklift.deployArtifacts.getArtifacts<IDeployArtifacts>();

  const sampleAv0 = locklift.deployArtifacts.getContract(artifacts.test.Sample.SampleA.v0);

  const details = await sampleAv0.methods.getDetails().call();
  console.log("details", details);
}
main()
  .then(() => process.exit(0))
  .catch(e => {
    console.log(e);
    process.exit(1);
  });

deploy contract with locklift-deploy-private plugin

// locklift.config.ts
import { LockliftConfig } from "locklift";
import { FactorySource } from "./build/factorySource";

import { DeployArtifactsExtension } from "locklift-deploy-artifacts";
import { LockliftConfigExtension, PrivateDeployerExtension } from "locklift-private-deploy";
import "locklift-deploy-artifacts";
import "locklift-private-deploy";

declare module "locklift" {
  export interface Locklift<FactorySource>
    extends DeployArtifactsExtension<FactorySource>,
      PrivateDeployerExtension<FactorySource> {}
  export interface LockliftConfig extends LockliftConfigExtension {}
}
declare global {
  const locklift: import("locklift").Locklift<FactorySource>;
}

const LOCAL_NETWORK_ENDPOINT = "http://localhost/graphql";

const VENOM_TESTNET_ENDPOINT = process.env.VENOM_TESTNET_ENDPOINT || "https://jrpc-testnet.venom.foundation/rpc";
const VENOM_TESTNET_TRACE_ENDPOINT =
  process.env.VENOM_TESTNET_TRACE_ENDPOINT || "https://gql-testnet.venom.foundation/graphql";

const config: LockliftConfig = {
  privateRPC: "https://private-rpc.com/rpc",
  // ...
}
// scripts/deploy.ts
async function main() {
  console.log("Starting Sample contract deployment...");

  const signer = (await locklift.keystore.getSigner("0"))!;

  const { contract: sample } = await locklift.deployArtifacts.deployContract(
    "SampleA",
    "latest",
    {
      contract: "Sample",
      publicKey: signer.publicKey,
      initParams: { _nonce: locklift.utils.getRandomNonce() },
      constructorParams: { _state: 0 },
      value: locklift.utils.toNano(1),
    },
    locklift.privateRPC.deployContract, // specify deploy function here
  );

  console.log("sample contract address:", sample.address.toString());
}

main()
  .then(() => process.exit(0))
  .catch(e => {
    console.log(e);
    process.exit(1);
  });

Package Sidebar

Install

npm i locklift-deploy-artifacts

Weekly Downloads

2

Version

1.1.1

License

Apache-2.0

Unpacked Size

127 kB

Total Files

21

Last publish

Collaborators

  • s0r0k