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
↳
Contract
Indexable
▪ [key: string
]: any
The function names on any given contract. Like "isClaimed", "merkleRoot", etc.
Constructors
constructor
• new Contract(addressOrName
, contractInterface
, signerOrProvider
)
example
Parameters
Name | Type | Description |
---|---|---|
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 |
Inherited from
Defined in
src/classes/Contract.ts:35