Skip to main content

Class: Contract

alpha Only accepts ABIS in JSON format. This allows for stronger typing and assurances of data-types Only read-only function calls currently supported.

example

import { Contract, JsonRpcProvider } from 'essential-eth';
// UNI airdrop contract
const contractAddress = '0x090D4613473dEE047c3f2706764f49E0821D256e';
const provider = new JsonRpcProvider();
// for more robust contract calls, provide a fallback:
// const provider = new FallthroughProvider(['bad', 'https://free-eth-node.com/api/eth']);

const JSONABI = [
{
inputs: [
{
internalType: 'uint256',
name: 'index',
type: 'uint256',
},
],
name: 'isClaimed',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
]

const contract = new Contract(
contractAddress,
JSONABI,
provider,
);

(async () => {
// prints boolean as to whether index 0 has claimed airdrop or not
console.log(await contract.isClaimed(0));
})()

Hierarchy

Indexable

[key: string]: any

The function names on any given contract. Like "isClaimed", "merkleRoot", etc.

Constructors

constructor

new Contract(addressOrName, contractInterface, signerOrProvider)

example

Parameters

NameTypeDescription
addressOrNamestringThe ethereum address of the smart-contract
contractInterfaceJSONABIThe JSON ABI of the smart-contract (like http://api.etherscan.io/api?module=contract&action=getabi&address=0x090d4613473dee047c3f2706764f49e0821d256e&format=raw)
signerOrProviderJsonRpcProviderAn instantiated essential-eth provider

Inherited from

BaseContract.constructor

Defined in

src/classes/Contract.ts:35