OPNet
    Preparing search index...

    Function getContract

    • Creates a new contract instance.

      Type Parameters

      Parameters

      • address: string | Address

        The address of the contract.

      • abi: BitcoinInterface | BitcoinInterfaceAbi

        The ABI of the contract.

      • provider: AbstractRpcProvider

        The provider for the contract.

      • Optionalnetwork: Network

        The network of the contract.

      • Optionalsender: Address

        Who is sending the transaction.

      Returns BaseContract<T> & Omit<T, keyof BaseContract<T>>

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