The properties of the contract.
The address of the contract.
The ABI of the contract.
The provider for the contract.
Optional
network: NetworkThe network of the contract.
Optional
sender: AddressWho is sending the transaction.
The contract instance.
const contractAddress: string | Address = 'bcrt1p9p97ftxmx25ehgltlfn2j8wmgxnm0gwjlm6p2wveytxc5pzgtspqx93dy5';
const senderAddress: Address = new Address([
40, 11, 228, 172, 219, 50, 169, 155, 163, 235, 250, 102, 169, 29, 219, 65, 167, 183, 161, 210,
254, 244, 21, 57, 153, 34, 205, 138, 4, 72, 92, 2,
]);
const provider: JSONRpcProvider = new JSONRpcProvider('https://regtest.opnet.org');
const contract: IOP20Contract = getContract<IOP20Contract>(
contractAddress,
OP_20_ABI,
provider,
networks.regtest,
senderAddress,
);
const balanceExample = await contract.balanceOf(
senderAddress
);
if ('error' in balanceExample) throw new Error('Error in fetching balance');
console.log('Balance:', balanceExample.decoded);
Creates a new contract instance.