Class Contract<E, V>

Base class for interacting with arbitrary contracts. Public version is Contract.

Type Parameters

  • E extends string = string

    union of update entrypoints

  • V extends string = string

    union of view entrypoints

Hierarchy

  • ContractBase<E, V>
    • Contract

Constructors

Properties

contractAddress: ContractAddress
contractName: ContractName
dryRunInstance: ContractDryRun<E>

The dry-run instance, accessible through ContractBase.dryRun

schema?: Schema<E>

Accessors

Methods

  • Check if the smart contract instance exists on the blockchain and whether it uses a matching contract name. Optionally a module reference can be provided to check if the contract instance uses this module.

    Throws

    If failing to communicate with the concordium node or if the instance does not exist on chain or fails the checks.

    Parameters

    • Optional options: ContractCheckOnChainOptions = {}

      Options for checking information on chain.

    Returns Promise<void>

  • Creates and sends a contract update transaction with parameter input to entrypoint.

    Throws

    If the query could not be invoked successfully.

    Returns

    The transaction hash of the update transaction

    Type Parameters

    • T

      The type of the input

    Parameters

    • entrypoint: EntrypointName.Type<E>

      The name of the receive function to invoke.

    • serializeInput: ((input: T) => ArrayBuffer)

      A function to serialize the input to bytes.

        • (input: T): ArrayBuffer
        • Parameters

          • input: T

          Returns ArrayBuffer

    • metadata: ContractTransactionMetadata

      Metadata to be used for the transaction (with defaults).

    • input: T

      Input for for contract function.

    • signer: AccountSigner

      An object to use for signing the transaction.

    Returns Promise<TransactionHash>

  • Creates a ContractUpdateTransactionWithSchema contract update transaction, holding the necessary parts to sign/submit to the chain.

    Throws

    If the query could not be invoked successfully.

    Returns

    Details necesary for submitting the contract update transaction.

    Type Parameters

    • T

      The type of the input

    Parameters

    • entrypoint: EntrypointName.Type<E>

      The name of the receive function to invoke.

    • serializeInput: ((input: T) => ArrayBuffer)

      A function to serialize the input to bytes.

        • (input: T): ArrayBuffer
        • Parameters

          • input: T

          Returns ArrayBuffer

    • metadata: CreateContractTransactionMetadata

      Metadata to be used for the transaction creation (with defaults).

    • input: T

      Input for for contract function.

    Returns ContractUpdateTransaction

  • Creates a ContractUpdateTransactionWithSchema contract update transaction, holding the necessary parts to sign/submit to the chain.

    Throws

    If the query could not be invoked successfully.

    Returns

    Details necessary for submitting the contract update transaction (with JSON to be serialized with corresponding schema)

    Type Parameters

    • T

      The type of the input

    • J extends SmartContractTypeValues

      The type of the input formatted as JSON compatible with the corresponding contract schema

    Parameters

    • entrypoint: EntrypointName.Type<E>

      The name of the receive function to invoke.

    • serializeInput: ((input: T) => ArrayBuffer)

      A function to serialize the input to bytes.

        • (input: T): ArrayBuffer
        • Parameters

          • input: T

          Returns ArrayBuffer

    • metadata: CreateContractTransactionMetadata

      Metadata to be used for the transaction creation (with defaults).

    • input: T

      Input for for contract function.

    • inputJsonFormatter: ((input: T) => J)

      A function to format the input as JSON format serializable by the contract schema.

        • (input: T): J
        • Parameters

          • input: T

          Returns J

    Returns {
        parameter: {
            hex: string;
            json: J;
        };
        payload: UpdateContractPayload;
        schema?: ContractSchema;
        type: Update;
    }

    • parameter: {
          hex: string;
          json: J;
      }

      Parameter of the update

      • hex: string

        Hex encoded parameter for the update

      • json: J

        JSON representation of the parameter to be used with the corresponding contract schema

    • payload: UpdateContractPayload

      The payload of the transaction, which will always be of type UpdateContractPayload

    • Optional schema?: ContractSchema

      The schema needed to serialize the parameter

    • type: Update

      The type of the transaction, which will always be of type Update

  • Get information on this smart contract instance.

    Throws

    if the InstanceInfo of the contract could not be found.

    Returns

    The instance info.

    Parameters

    • Optional blockHash: BlockHash

      Hash of the block to check information at. When not provided the last finalized block is used.

    Returns Promise<InstanceInfo>

  • Invokes entrypoint view function on contract.

    Throws

    If the query could not be invoked successfully.

    Returns

    The transaction hash of the update transaction

    Type Parameters

    • T

      The type of the input

    • R

      The type the invocation response should be deserialized into.

    Parameters

    • entrypoint: EntrypointName.Type<V>

      The name of the view function to invoke.

    • serializeInput: ((input: T) => ArrayBuffer)

      A function to serialize the input to bytes.

        • (input: T): ArrayBuffer
        • Parameters

          • input: T

          Returns ArrayBuffer

    • deserializeResponse: ((value: string) => R)

      A function to deserialize the value returned from the view invocation.

        • (value: string): R
        • Parameters

          • value: string

          Returns R

    • input: T

      Input for for contract function.

    • Optional blockHash: BlockHash

      The hash of the block to perform the invocation of. Defaults to the latest finalized block on chain.

    Returns Promise<R>

  • Creates a new Contract instance by querying the node for the necessary information through the supplied grpcClient.

    Throws

    If InstanceInfo could not be received for the contract,

    or if the contract name could not be parsed from the information received from the node.

    Type Parameters

    • E extends string = string

    • V extends string = string

    Parameters

    • grpcClient: ConcordiumGRPCClient

      The client used for contract invocations and updates.

    • contractAddress: ContractAddress

      Address of the contract instance.

    • Optional schema: Schema<E>

      The schema of the contract, either defined as parameter schemas per entrypoint E or as a single module schema. If no schema is defined, an attempt to get an embedded schema from the contract is made.

    Returns Promise<Contract<E, V>>

  • Helper function for getting the name of a contract

    Throws

    if the InstanceInfo of the contract could not be found.

    Returns

    the name of the contract.

    Parameters

    • grpcClient: ConcordiumGRPCClient

      The GRPC client for accessing a node.

    • contractAddress: ContractAddress

      The address of the contract.

    Returns Promise<ContractName>

Generated using TypeDoc