Crate concordium_cis2

Source
Expand description

This library provides types and functions for working with the Concordium Token Standard CIS2.

It contains types for the parameters for each of the contract functions and types for each event. Each type have implemented serialization according to CIS2. Additionally the crate exports an CIS2Error wrapper type which can be used to wrap and extend a custom error type. This will ensure the CIS2 errors have the correct error codes.

§Example using TransferParams

type TransferParameter = TransferParams<TokenIdVec>;

#[receive(contract = "MyTokenContract", name = "transfer", parameter = "TransferParameter", enable_logger)]
fn contract_transfer<A: HasActions>(
    ctx: &impl HasReceiveContext,
    logger: &mut impl HasLogger,
    state: &mut State,
) -> ContractResult<A> {
    // Parse the parameter.
    let TransferParams(transfers) = ctx.parameter_cursor().get()?;
    // ...
    Ok(A::accept())
}

§Features

This crate has features std, u256_amount, and serde. The first one is default. When the u256_amount feature is enabled the type TokenAmountU256 is defined and implements the IsTokenAmount interface. The serde features derives serde::Serialize and serde::Deserialize for a variety of types.

Structs§

AdditionalData
Additional information to include with a transfer.
BalanceOfQuery
A query for the balance of a given address for a given token.
BalanceOfQueryParams
The parameter type for the contract function balanceOf.
BalanceOfQueryResponse
The response which is sent back when calling the contract function balanceOf. It consists of the list of results corresponding to the list of queries.
BurnEvent
An untagged event of some amount of a token type being burned. For a tagged version, use Cis2Event.
Cis2Client
Client for interacting with CIS2 compliant contracts.
InvalidStandardIdentifierError
String is not a valid standard identifier. Ensure the length is less than 256 and it only contains ASCII characters.
MetadataUrl
The location of the metadata and an optional hash of the content.
MintEvent
An untagged event of tokens being minted, could be a new token type or extending the total supply of existing token. For a tagged version, use Cis2Event.
OnReceivingCis2DataParams
Specific parameter type for a contract function which receives CIS2 tokens with a specific type D for the AdditionalData.
OnReceivingCis2Params
Generic parameter type for a contract function which receives CIS2 tokens.
OperatorOfQuery
A query for the operator of a given address for a given token.
OperatorOfQueryParams
The parameter type for the contract function operatorOf.
OperatorOfQueryResponse
The response which is sent back when calling the contract function operatorOf. It consists of the list of result in the same order and length as the queries in the parameter.
StandardIdentifier
Identifier for a smart contract standard. Consists of a string of ASCII characters up to a length of 255.
StandardIdentifierOwned
Owned identifier for a smart contract standard. Consists of a string of ASCII characters up to a length of 255.
SupportsQueryParams
The parameter type for the contract function supports.
SupportsQueryResponse
The response which is sent back when calling the contract function supports. It consists of a list of results corresponding to the list of queries.
TokenAmountU8
TokenAmountU16
TokenAmountU32
TokenAmountU64
TokenAmountU128
TokenAmountU256
TokenIdFixed
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenIdU8
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenIdU16
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenIdU32
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenIdU64
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenIdUnit
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenIdVec
Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
TokenMetadataEvent
An untagged event for setting the metadata for a token. For a tagged version, use Cis2Event.
TokenMetadataQueryParams
The parameter type for the contract function tokenMetadata.
TokenMetadataQueryResponse
The response which is sent back when calling the contract function tokenMetadata. It consists of the list of results corresponding to the list of queries.
Transfer
A single transfer of some amount of a token.
TransferEvent
An untagged event of a transfer of some amount of tokens from one address to another. For a tagged version, use Cis2Event.
TransferParams
The parameter type for the contract function transfer.
UpdateOperator
A single update of an operator.
UpdateOperatorEvent
An untagged event of an update to an operator address for an owner address. For a tagged version, use Cis2Event.
UpdateOperatorParams
The parameter type for the contract function updateOperator.

Enums§

Cis2ClientError
Errors which can be returned by the Cis2Client.
Cis2Error
The different errors the contract can produce.
Cis2Event
Tagged CIS2 event to be serialized for the event log.
OperatorUpdate
The update to an the operator.
Receiver
The receiving address for a transfer, similar to the Address type, but contains extra information when the receiver address is a contract.
SupportResult
The query result type for whether a smart contract supports a standard.

Constants§

BURN_EVENT_TAG
Tag for the CIS2 Burn event.
CIS0_STANDARD_IDENTIFIER
The standard identifier for the CIS-0: Standard Detection.
CIS1_STANDARD_IDENTIFIER
The standard identifier for the CIS-1: Concordium Token Standard.
CIS2_STANDARD_IDENTIFIER
The standard identifier for the CIS-2: Concordium Token Standard 2.
MINT_EVENT_TAG
Tag for the CIS2 Mint event.
TOKEN_METADATA_EVENT_TAG
Tag for the CIS2 TokenMetadata event.
TRANSFER_EVENT_TAG
Tag for the CIS2 Transfer event.
UPDATE_OPERATOR_EVENT_TAG
Tag for the CIS2 UpdateOperator event.

Traits§

IsTokenAmount
Trait for marking types as CIS2 token amounts. For a type to be a valid CIS2 token amount it must implement SchemaType and Serialize, using the LEB128 unsigned integer encoding constrained to at most 37 bytes.
IsTokenId
Trait for marking types as CIS2 token IDs. For a type to be a valid CIS2 token ID it must implement SchemaType and Serialize, such that the first byte indicates how many bytes is used to represent the token ID, followed by this many bytes for the token ID.