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§
- Additional
Data - Additional information to include with a transfer.
- Balance
OfQuery - A query for the balance of a given address for a given token.
- Balance
OfQuery Params - The parameter type for the contract function
balanceOf
. - Balance
OfQuery Response - 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. - Burn
Event - An untagged event of some amount of a token type being burned.
For a tagged version, use
Cis2Event
. - Cis2
Client - Client for interacting with CIS2 compliant contracts.
- Invalid
Standard Identifier Error - String is not a valid standard identifier. Ensure the length is less than 256 and it only contains ASCII characters.
- Metadata
Url - The location of the metadata and an optional hash of the content.
- Mint
Event - 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
. - OnReceiving
Cis2 Data Params - Specific parameter type for a contract function which receives CIS2 tokens with a specific type D for the AdditionalData.
- OnReceiving
Cis2 Params - Generic parameter type for a contract function which receives CIS2 tokens.
- Operator
OfQuery - A query for the operator of a given address for a given token.
- Operator
OfQuery Params - The parameter type for the contract function
operatorOf
. - Operator
OfQuery Response - 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. - Standard
Identifier - Identifier for a smart contract standard. Consists of a string of ASCII characters up to a length of 255.
- Standard
Identifier Owned - Owned identifier for a smart contract standard. Consists of a string of ASCII characters up to a length of 255.
- Supports
Query Params - The parameter type for the contract function
supports
. - Supports
Query Response - 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. - Token
Amount U8 - Token
Amount U16 - Token
Amount U32 - Token
Amount U64 - Token
Amount U128 - Token
Amount U256 - Token
IdFixed - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
IdU8 - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
IdU16 - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
IdU32 - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
IdU64 - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
IdUnit - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
IdVec - Token Identifier, which combined with the address of the contract instance, forms the unique identifier of a token type.
- Token
Metadata Event - An untagged event for setting the metadata for a token.
For a tagged version, use
Cis2Event
. - Token
Metadata Query Params - The parameter type for the contract function
tokenMetadata
. - Token
Metadata Query Response - 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.
- Transfer
Event - An untagged event of a transfer of some amount of tokens from one address to
another. For a tagged version, use
Cis2Event
. - Transfer
Params - The parameter type for the contract function
transfer
. - Update
Operator - A single update of an operator.
- Update
Operator Event - An untagged event of an update to an operator address for an owner address.
For a tagged version, use
Cis2Event
. - Update
Operator Params - The parameter type for the contract function
updateOperator
.
Enums§
- Cis2
Client Error - Errors which can be returned by the
Cis2Client
. - Cis2
Error - The different errors the contract can produce.
- Cis2
Event - Tagged CIS2 event to be serialized for the event log.
- Operator
Update - 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.
- Support
Result - 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§
- IsToken
Amount - 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.
- IsToken
Id - Trait for marking types as CIS2 token IDs.
For a type to be a valid CIS2 token ID it must implement
SchemaType
andSerialize
, 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.