@drizzle-utils/get-contract-instance

0.2.0 • Public • Published

@drizzle-utils/get-contract-instance

Retrieves a Web3.js contract instance.

You can pass in a contract artifact JSON generated by Truffle (i.e. truffle compile and truffle migrate), or you can pass in the contract ABI and address.

A warning will let you know if a deployed address is not supplied, to suppress the warning, pass in suppressWarnings: true into the options object.

Usage

Import the helper function:

import getContractInstance from "@drizzle-utils/get-contract-instance";

With Truffle artifact

import SimpleStorage from "./SimpleStorage.json";

const instance = await getContractInstance({
  web3,
  artifact: SimpleStorage,
});

With ABI and contract address

const instance = await getContractInstance({
  web3,
  abi: contractAbi,
  address: "0x..."
});

With ABI only

const instance = await getContractInstance({
  web3,
  abi: contractAbi,
});

Note that this instance will not have a contract address attached to it.

Readme

Keywords

none

Package Sidebar

Install

npm i @drizzle-utils/get-contract-instance

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

11.7 kB

Total Files

9

Last publish

Collaborators

  • adrianmcli
  • cds-amal
  • discriskandbisque
  • honestbonsai