CW721

Introduction

The CW721 ADO is a smart contract to allow users to launch their own custom NFT projects. In addition to the standard CW721 messages, we have added some custom logic to further extend the utility and function of the contract.

The CW721 ADO is one of the base ADOs meaning it can interact with a large number of other ADOs such as the marketplace, crowdfund, auction, CW721 timelock and many more.

The contract has implemented a custom TransferAgreement message to allow the buying/selling of tokens between two parties throught the CW721 ADO itself.

Ado_type: cw721

Version: 2.0.3-beta.1

InstantiateMsg

pub struct InstantiateMsg {
    pub name: String,
    pub symbol: String,
    pub minter: AndrAddr,
    pub kernel_address: String,
    pub owner: Option<String>,
}
NameTypeDescription

name

String

The name of the NFT collection.

symbol

String

The symbol of the NFT collection.

minter

The address allowed to mint NFTs.

kernel_address

String

Contract address of the kernel contract to be used for AMP messaging. Kernel contract address can be found in our deployed contracts.

owner

Option<String>

Optional address to specify as the owner of the ADO being created. Defaults to the sender if not specified.

ExecuteMsg

Mint

Mints a new NFT.

Only available to the defined minter in the InstantiateMsg.

pub enum ExecuteMsg  {
   Mint {
    pub token_id: String,
    pub owner: String,
    pub token_uri: Option<String>,
    pub extension: TokenExtension,
   }
}
NameTypeDescription

token_id

String

Unique Id of the NFT.

owner

String

The address of the NFT owner.

token_uri

Option<String>

URI pointing to the NFT metadata. You can read more about the NFT token URI and metadata standards here.

extension

TokenExtension

Any custom extension used by this contract. Here we use TokenExtension.

TokenExtension

Extension that can be added to an NFT when minting.

pub struct TokenExtension {
   pub publisher: String,
}
NameTypeDescription

publisher

String

The entity to assign as the publisher of the NFT e.g. "Andromeda" or "Bob". (Immutable).

BatchMint

Mint several NFTs at once.

pub enum ExecuteMsg {
   BatchMint {
        tokens: Vec<MintMsg>,
    }
}
NameTypeDescription

tokens

Vector of MintMsg. Similar to minting one token, but allows minting of many tokens in one go.

TransferAgreement

Assigns a TransferAgreement for a token. If the agreement field is not set, the message will remove any previously set agreements on the token (Instead of making a new RemoveAgreement message).

Only available to the token owner.

pub enum ExecuteMsg {
       TransferAgreement {
           token_id: String,
           agreement: Option<TransferAgreement>,
        }
  }
NameTypeDescription

token_id

String

The token Id of the NFT we want to add an agreement for.

agreement

The agreement for the token containing the selling price and the address allowed to purchase the token. If not specified then any previously set agreement is removed from the token.

TransferAgreement

The purchaser may use the TransferNft message for this token as long as funds are provided equaling the amount defined in the agreement.

If the purchaser is set to "*" then anyone can complete the TransferAgreement (Anyone can buy the NFT).

pub struct TransferAgreement {
    pub amount: Coin,
    pub purchaser: String,
}
NameTypeDescription

amount

The amount required for the purchaser to transfer ownership of the token.

purchaser

String

The address of the purchaser that is allowed to purchase the token.

TransferNft

A CW721 compliant transfer method. Transfers ownership of a minted token.

Archived tokens cannot be transferred.

Only available to the contract owner, an approved operator, or a purchaser in a TransferAgreement for the given token.

pub enum ExecuteMsg {
    TransferNft {
        recipient: AndrAddr,
        token_id: String,
    }
}
NameTypeDescription

recipient

The address to receive the NFT.

token_id

String

The token Id of the token to be transferred.

SendNft

A CW721 compliant send method. Sends ownership of a minted token to an external contract.

Only available to the token owner/operator/approved address.

pub enum ExecuteMsg {
    SendNft {
        contract: AndrAddr,
        token_id: String,
        msg: Binary,
    }
}
NameTypeDescription

contract

The address of the receiving contract.

token_id

String

The Id of the token to be sent.

msg

Binary

A message to be sent to the receiving contract.

Burn

Destroys any token data related to an token Id. The Id of the token is still reserved.

Cannot be undone.

Only available to the token owner.

pub enum ExecuteMsg {
    Burn {
        token_id: String,
    },
}
NameTypeDescription

token_id

String

The Id of the token to burn.

Archive

Archives an token, making it immutable in any respect. Once an token is archived it cannot be edited, transferred or burnt.

Cannot be undone.

Only available to the token owner.

pub enum ExecuteMsg {
    Archive {
        token_id: String,
    }
}
NameTypeDescription

token_id

String

The Id of the token to archive.

Approve

A CW721 compliant approve method. Approves a given address as an operator for the token, allowing them to transfer, burn or archive the token.

Only available to the token owner/operator.

pub enum ExecuteMsg {
    Approve {
        spender: String,
        token_id: String,
        expires: Option<Expiration>,
    }
}
NameTypeDescription

spender

String

The address to be authorised as an operator.

token_id

String

The id of the token for which to assign the spender as an operator.

expires

Option<Expiration>

An optional expiration for the approval. Defaults to never.

Revoke

A CW721 compliant revoke method. Revokes operator privileges for a given address.

Only available to the token owner/operator.

pub enum ExecuteMsg {
    Revoke {
        spender: String,
        token_id: String,
    }
}
NameTypeDescription

spender

String

The address of the operator for which to revoke privileges.

token_id

String

The Id of the token for which to revoke operator privileges.

ApproveAll

A CW721 compliant approve all method. Approves a given address as an operator for all tokens owned by the sender.

Will overwrite any approval currently assigned to the operator's address.

pub enum ExecuteMsg {
    ApproveAll {
        operator: String,
        expires: Option<Expiration>,
    }
}
NameTypeDescription

operator

String

The address to be authorised as an operator.

expires

Option<Expiration>

An optional expiration for the approval. Defaults to never.

RevokeAll

A CW721 compliant revoke all method. Revokes an operator's privileges for any tokens owned by the sender.

pub enum ExecuteMsg {
    RevokeAll {
        operator: String,
    }
}
NameTypeDescription

operator

String

The address of the operator for which to revoke privileges.

Base Executes

The rest of the execute messages can be found in the ADO Base section.

QueryMsg

Minter

Queries the current minter of the contract.

pub enum QueryMsg{
    #[returns(MinterResponse)]
    Minter{},
 }

MinterResponse

pub struct MinterResponse{
        minter: Option<String>,
 }

OwnerOf

A CW721 compliant "owner of" query. Queries the current owner of a given token Id.

pub enum QueryMsg {
    #[returns(OwnerOfResponse)]
    OwnerOf {
        token_id: String,
        include_expired:bool,
    }
}
NameTypeDescription

token_id

String

The Id of the token to query.

include_expired

bool

Whether to include any expired owners.

OwnerOfResponse

pub struct OwnerOfResponse {
    pub owner: String,
    pub approvals: Vec<Approval>,
}
NameTypeDescription

owner

String

The owner of the queried token.

approvals

An array of all approvals for the token.

Approval

pub struct Approval {
    pub spender: String,
    pub expires: Expiration,
}
NameTypeDescription

spender

String

The address that is approved.

expires

The expiration for the approval.

Operator

Returns the approval of a given operator for all tokens of an owner. Errors if no approvals are set.

pub enum QueryMsg {
   #[returns(cw721::OperatorResponse)]
   Operator {
        owner: String,
        operator: String,
        include_expired: Option<bool>,
    }
 }
NameTypeDescription

owner

String

The address of the NFTs owner.

operator

String

The address of the operator that has approvals over the specified owner NFTs.

include_expired

Option<bool>

Whether to include any expired approvals.

OperatorResponse

#[cw_serde]
pub struct OperatorResponse {
    pub approval: Approval,
}

Returns an Approval struct.

AllOperators

List all operators that can access all of the owner's tokens.

pub enum QueryMsg {
    #[returns(OperatorsResponse)]
    AllOperators {
        owner: String,
        include_expired: Option<bool>,
        start_after: Option<String>,
        limit: Option<u32>,
    },
NameTypeDescription

owner

String

The address of the owner for which to query operators.

include_expired

Option<bool>

Whether to include any expired approvals.

limit

Option<u32>

An optional limit on how many approvals are returned. The default limit is 10 and the maximum limit allowed is 100.

start_after

Option<String>

An optional address for which to start after, used for pagination.

OperatorsResponse

pub struct OperatorsResponse {
    pub operators: Vec<Approval>,
}
NameTypeDescription

approvals

An array of all approvals for the given owner address.

NumTokens

A CW721 compliant "num tokens" query. Queries the amount of tokens minted by the contract.

pub enum QueryMsg {
    #[returns(NumTokensResponse)]
    NumTokens {}
}

NumTokensResponse

pub struct NumTokensResponse {
    pub count: u64,
}
NameTypeDescription

count

u64

The amount of tokens minted by the contract.

NftInfo

A CW721 compliant "nft info" query. Queries the stored info of a token.

pub enum QueryMsg {
    #[returns(NftInfoResponse<TokenExtension>)]
    NftInfo {
        token_id: String,
    }
}
NameTypeDescription

token_id

String

The id of the token.

NftInfoResponse

pub struct NftInfoResponse<T> {
    pub token_uri: Option<String>,
    pub extension: T,
}
NameTypeDescription

token_uri

String

Universal resource identifier for this token.

extension

T (Generic type)

Any extension being used by the contract to add custom metadata to the tokens.

AllNftInfo

A CW721 compliant "all nft info" query. Queries all stored info of an token.

pub enum QueryMsg {
    #[returns(AllNftInfoResponse<TokenExtension>)]
    AllNftInfo {
        token_id: String,
        include_expired: Option<bool>
    }
}
NameTypeDescription

token_id

String

The token id of the NFT.

include_expired

Option<bool>

Whether to include any expired approvals.

AllNftInfoResponse

pub struct AllNftInfoResponse<T> {
    pub access: OwnerOfResponse,
    pub info: NftInfoResponse<T>,
}
NameTypeDescription

access

The address that can transfer the token.

info

Data on the token itself.

IsArchived

Checks if the token with the specified token_id is archived.

pub enum QueryMsg {
   #[returns(bool)]
   IsArchived {
         token_id: String,
        }
 }
NameTypeDescription

token_id

String

The token_id of the NFT we want to check.

Returns a bool value.

TransferAgreement

Checks if the token has a TransferAgreement .

pub enum QueryMsg {
      #[returns(Option<TransferAgreement>)]
      TransferAgreement {
        token_id: String,
    }
}
NameTypeDescription

token_id

String

The token_id of the nft we want to check.

Returns None if no TransferAgreement is found, and the TransferAgreement struct otherwise.

Tokens

Queries all the tokens of a particular owner.

pub enum QueryMsg {
    #[returns(TokensResponse)]
    Tokens {
        owner: String,
        start_after: Option<String>,
        limit: Option<u32>,
    }
}
NameTypeDescription

owner

String

The address that we want to check the tokens of

start_after

Option<String>

An optional address for which to start after, used for pagination.

limit

Option<u32>

Optional limit to the number of tokens queried. It is set by default as 10 and can be set up to 30.

TokensResponse

Contains all token_ids in lexicographical ordering. If there are more than limit, use start_from in future queries to achieve pagination.

pub struct TokensResponse {
    pub tokens: Vec<String>,
}

AllTokens

Queries the tokens minted by the contract.

 pub enum QueryMsg {
    #[returns(TokensResponse)]
    AllTokens {
        start_after: Option<String>,
        limit: Option<u32>,
        }
 }
NameTypeDescription

start_after

Option<String>

An optional address for which to start after, used for pagination.

limit

Option<u32>

Optional limit to the number of tokens queried. It is set by default as 10 and can be set up to 30.

TokensResponse

Contains all token_ids in lexicographical ordering. If there are more than limit, use start_from in future queries to achieve pagination.

pub struct TokensResponse {
    pub tokens: Vec<String>,
}

ContractInfo

Queries the name and symbol of the token collection.

pub enum QueryMsg {
    #[returns(ContractInfoResponse)]
    ContractInfo {}
}

ContractInfoResponse

pub struct CotractInfoResponse {
    pub name: String,
    pub symbol: String,
}
NameTypeDescription

name

String

The name of the contract.

symbol

String

The assigned symbol of the contract.

Approval

Queries the spender's approval to check for the expiration.

 pub enum QueryMsg {
 Approval {
        token_id: String,
        spender: String,
        include_expired: Option<bool>,
    }
 }
NameTypeDescription

token_id

String

The token Id of the NFT to check.

spender

String

The address to check the approvals.

include_expired

Option<bool>

Optional flag to include the expired approvals. Defaults to false.

ApprovalResponse

pub struct ApprovalResponse {
    pub approval: Approval,
}
NameTypeDescription

approval

Approval

The approved spender and the expiration for the approval.

pub struct Approval {
    pub spender: String,
    pub expires: Expiration,
}
NameTypeDescription

spender

String

Account that can transfer/send the token

expires

When the Approval expires. Might be Expiration::never.

Approvals

Returns all the approvals a token has.

pub enum QueryMsg{
  Approvals {
        token_id: String,
        include_expired: Option<bool>,
    }
 }
NameTypeDescription

token_id

String

The token Id of the NFT to get approvals for.

include_expired

Option<bool>

Optional flag to include the expired approvals. Defaults to false.

ApprovalsResponse

pub struct ApprovalsResponse {
    pub approvals: Vec<Approval>,
}

Return a vector of Approval.

Base Queries

The rest of the query messages can be found in the ADO Base section.

Additional Resources

GithubWebsite