supra-ts-sdk - v2.0.0
    Preparing search index...

    Class ContractBeta

    The Contract class provides methods for interacting with the Supra network.

    Hierarchy (View Summary)

    Index
    • Beta

      The constructor function takes a NetworkConfig object as a parameter and assigns it to the networkInformation property.

      Parameters

      • networkInformation: NetworkConfig

        A NetworkConfig object that contains information about the network on which the Supra client is running.

      Returns Contract

      import { SupraClient,Network } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
    • Beta

      The fromABI function takes an array of MoveModule (Contract ABI) objects as input.

      contracts.<module name>.view.<function>(args) calls a view function and returns its results converted to TypeScript values, as methods.view does, including the type parameters of generic views: a type argument that an earlier node reads differently needs a node from supra_node_v12.0.0, and the call throws SupraError before the view request on an earlier node (see methods.view). contracts.<module name>.entry.<function>(args) builds, signs and submits an entry function transaction: the &signer argument is the sender's SupraAccount, optionalTransactionPayloadArgs and enableTransactionWaitAndSimulationArgs are optional, the sequence number comes from the client's counter unless optionalTransactionPayloadArgs.sequenceNumber is set, the client submits its calls from one account one after another, and the client checks the chain ID of its node before it signs; see SupraConfig. Without a maxGas the max gas is estimated (see OptionalTransactionPayloadArgs).

      Type Parameters

      • T extends readonly Readonly<
            {
                address: string;
                name: string;
                friends: readonly `${string}::${string}`[];
                exposed_functions: readonly Readonly<
                    {
                        name: string;
                        visibility: Readonly;
                        is_entry: Readonly<boolean>;
                        is_view: Readonly<boolean>;
                        generic_type_params: readonly Readonly<
                            { constraints: readonly Readonly<(...)>[] },
                        >[];
                        params: readonly string[];
                        return: readonly string[];
                    },
                >[];
                structs: readonly Readonly<
                    {
                        name: string;
                        is_native: Readonly<boolean>;
                        is_event?: Readonly<boolean | undefined>;
                        is_enum?: Readonly<boolean | undefined>;
                        abilities: readonly Readonly<MoveAbility>[];
                        generic_type_params: readonly Readonly<
                            { constraints: readonly Readonly<(...)>[] },
                        >[];
                        fields: readonly Readonly<{ name: string; type: string }>[];
                    },
                >[];
            },
        >[]

      Parameters

      • abis: T

        An array of MoveModule (Contract ABI) objects.

      Returns { contracts: ContractsFromABI<T> }

      An object with a contracts property which contains view and entry properties.

      From a call, when the module name is not in abis.

      import { Network, SupraClient } from "supra-ts-sdk";

      const COIN_ABI = {
      address: "0x1",
      name: "coin",
      friends: [],
      exposed_functions: [
      {
      name: "balance",
      visibility: "public",
      is_entry: false,
      is_view: true,
      generic_type_params: [{ constraints: [] }],
      params: ["address"],
      return: ["u64"],
      },
      ],
      structs: [],
      } as const;

      const supra = new SupraClient({ network: Network.TESTNET });

      async function runExample() {
      const instance = supra.contract.fromABI([COIN_ABI] as const);
      let balance = await instance.contracts.coin.view.balance({
      functionArguments: ["0x10cdf6e0c4c5c762bb23be3eac5c7eaa272c1b4abe0573cd1386c5632b7992ca"],
      typeArguments: ["0x1::supra_coin::SupraCoin"]
      })
      console.log("Balance:", balance[0]);
      }

      runExample().catch(console.error);