Class CIS2Contract

Contains methods for performing operations on CIS-2 smart contracts.

Hierarchy

  • CISContract<Updates, Views, CIS2DryRun>
    • CIS2Contract

Constructors

Properties

contractAddress: ContractAddress
contractName: ContractName
dryRunInstance: CIS2DryRun

The dry-run instance accessible through the CISContract.dryRun dryRun getter

schema: Record<"transfer" | "updateOperator", string> = ...

Accessors

  • get dryRun(): D
  • A dry-run instance, providing access to methods for performing dry-run invocations of update instructions.

    Returns D

Methods

  • Invokes CIS-2 "balanceOf" with a single query.

    Throws

    If the query could not be invoked successfully.

    Returns

    The balance corresponding to the query.

    Parameters

    • query: BalanceOfQuery

      The query object specifying the details of the query.

    • Optional blockHash: BlockHash

      The hash of the block to perform the query at. Defaults to the latest finalized block.

    Returns Promise<bigint>

  • Invokes CIS-2 "balanceOf" with a list of queries.

    Throws

    If the query could not be invoked successfully.

    Returns

    A list of balances corresponding to and ordered by the list of queries.

    Parameters

    • queries: BalanceOfQuery[]

      A list of query objects, each specifying the details of a query.

    • Optional blockHash: BlockHash

      The hash of the block to perform the query at. Defaults to the latest finalized block.

    Returns Promise<bigint[]>

  • 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<Updates>

      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

    The transaction hash of the update transaction

    Type Parameters

    • T

    Parameters

    • entrypoint: EntrypointName.Type<Updates>

      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

    The transaction hash of the update transaction

    Type Parameters

    Parameters

    • entrypoint: EntrypointName.Type<Updates>

      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 ContractUpdateTransactionWithSchema<J>

  • 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<Views>

      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>

  • Invokes CIS-2 "operatorOf" with a single query.

    Throws

    If the query could not be invoked successfully.

    Returns

    Whether the specified address is an operator of the specified owner.

    Parameters

    • query: OperatorOfQuery

      The query object specifying the details of the query.

    • Optional blockHash: BlockHash

      The hash of the block to perform the query at. Defaults to the latest finalized block.

    Returns Promise<boolean>

  • Invokes CIS-2 "operatorOf" with a list of queries.

    Throws

    If the query could not be invoked successfully.

    Returns

    As list of boolean results, each detailing whether the specified address is an operator of the specified owner for the corresponding query. The list is ordered by the corresponding query.

    Parameters

    • queries: OperatorOfQuery[]

      A list of query objects, each specifying the details of a query.

    • Optional blockHash: BlockHash

      The hash of the block to perform the query at. Defaults to the latest finalized block.

    Returns Promise<boolean[]>

  • Invokes CIS-2 "tokenMetadata" with a single token ID.

    Throws

    If the query could not be invoked successfully.

    Returns

    An object containing the URL of the token metadata.

    Parameters

    • tokenId: string

      The ID of the token to get the metadata URL for.

    • Optional blockHash: BlockHash

      The hash of the block to perform the query at. Defaults to the latest finalized block.

    Returns Promise<CIS2.MetadataUrl>

  • Invokes CIS-2 "tokenMetadata" with a list of token ID's.

    Throws

    If the query could not be invoked successfully.

    Returns

    A list of objects containing URL's for token metadata for the corresponding token. The list is ordered by the token ID's given by tokenIds input parameter.

    Parameters

    • tokenIds: string[]

      A list of ID's of the tokens to get metadata URL's for.

    • Optional blockHash: BlockHash

      The hash of the block to perform the query at. Defaults to the latest finalized block.

    Returns Promise<CIS2.MetadataUrl[]>

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

    Throws

    If InstanceInfo could not be received for the contract, if the contract does not support the CIS-2 standard, or if the contract name could not be parsed from the information received from the node.

    Parameters

    • grpcClient: ConcordiumGRPCClient

      The client used for contract invocations and updates.

    • contractAddress: ContractAddress

      Address of the contract instance.

    Returns Promise<CIS2Contract>

  • 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>

  • Helper function for getting the InstanceInfo of a contract

    Throws

    if the InstanceInfo of the contract could not be found.

    Returns

    the instance info.

    Parameters

    • grpcClient: ConcordiumGRPCClient

      The GRPC client for accessing a node.

    • contractAddress: ContractAddress

      The address of the contract.

    Returns Promise<InstanceInfo>

Generated using TypeDoc