Skip to content

Contract

Defined in: classes/Contract.ts:159

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));
})()

Extends

Indexable

[key: string]: any

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

Constructors

Constructor

new Contract(addressOrName, contractInterface, signerOrProvider): Contract

Defined in: classes/Contract.ts:35

Parameters

addressOrName

string

The ethereum address of the smart-contract

contractInterface

JSONABI

The JSON ABI of the smart-contract (like http://api.etherscan.io/api?module=contract&action=getabi&address=0x090d4613473dee047c3f2706764f49e0821d256e&format=raw)

signerOrProvider

JsonRpcProvider

An instantiated essential-eth provider

Returns

Contract

Example

Inherited from

BaseContract.constructor