CW-SDK's bank contract will manage both fungible and nonfungible tokens.
- Each fungible token is identified by a
denom
- Each nonfungible token is identified by a tuple
(denom, sequence)
where sequence is au64
; the 1st token in the collection gets a sequence of0
, the 2nd gets1
, so on
An NFT collection cannot share the same denom with a fungible token.
struct Coin {
pub denom: String,
pub amount: Uint128,
}
struct Nft {
pub denom: String,
pub sequence: u64,
}
The bank contract stores user coin and NFT holdings in the following mapping:
// fungible token balances
// (user_addr, denom) => balance
const COIN_BALANCES: Map<(&Addr, &str), Uint128>;
// nonfungible token balances
// (user_addr, denom, sequence) => Empty
const NFT_BALANCES: Map<(&Addr, &str, u64), Empty>;
The user can send any number of coins and NFTs in a single action by calling the bank contract with the following message:
enum BankExecuteMsg {
Send {
recipient: String,
coins: Vec<Coin>,
nfts: Vec<Nft>,
},
}
The WasmMsg::{Instantiate, Execute}
will be extended to allow transferring NFTs:
enum WasmMsg {
Instantiate {
code_hash: Binary,
msg: Binary,
funds: Vec<Coin>,
nfts: Vec<Nft>, // new!
admin: Option<String>,
salt: Option<Binary>,
},
Execute {
contract: String,
msg: Binary,
funds: Vec<Coin>,
nfts: Vec<Nft>, // new!
},
}
MessageInfo
will be extended to include NFTs as well:
struct MessageInfo {
pub sender: Addr,
pub funds: Vec<Coin>,
pub nfts: Vec<Nft>, // new!
}