#asset #mocking #assets


Helper library for interacting with Cosmos assets (native coins and CW20 tokens)

16 releases (10 stable)

3.0.0 Feb 3, 2023
2.4.0 Nov 8, 2022
2.3.0 Sep 5, 2022
2.2.0 Jul 10, 2022
0.3.1 Dec 31, 2021

#787 in Magic Beans

Download history 1654/week @ 2023-07-05 481/week @ 2023-07-12 659/week @ 2023-07-19 1324/week @ 2023-07-26 577/week @ 2023-08-02 893/week @ 2023-08-09 822/week @ 2023-08-16 1327/week @ 2023-08-23 1723/week @ 2023-08-30 1255/week @ 2023-09-06 1797/week @ 2023-09-13 795/week @ 2023-09-20 970/week @ 2023-09-27 630/week @ 2023-10-04 853/week @ 2023-10-11 1268/week @ 2023-10-18

3,972 downloads per month
Used in 38 crates (33 directly)


1.5K SLoC


A unified representation of various types of Cosmos fungible assets, and helper functions for interacting with them


Contents of this repository are open source under GNU Public License v3.


A unified representation of various types of Cosmos fungible assets, and helper functions for interacting with them

Basic usage

The following code generates messages the sends some SDK coins and CW20 tokens to a recipient:

use cosmwasm_std::{Api, Response};
use cw_asset::{Asset, AssetError};

fn transfer_two_assets(api: &dyn Api) -> Result<Response, AssetError> {
    let asset1 = Asset::native("uusd", 12345u128);
    let msg1 = asset1.transfer_msg("recipient_addr")?;

    let asset2 = Asset::cw20(api.addr_validate("token_addr")?, 67890u128);
    let msg2 = asset1.transfer_msg("recipient_addr")?;

        .add_attribute("asset_sent", asset1.to_string())
        .add_attribute("asset_sent", asset2.to_string()))

Asset list

An AssetList struct is also provided for dealing with multiple assets at the same time:

use cosmwasm_std::{Api, Response};
use cw_asset::{Asset, AssetError, AssetList};

fn transfer_multiple_assets(api: &dyn Api) -> Result<Response, AssetError> {
    let assets = AssetList::from(vec![
        Asset::native("uusd", 12345u128),
        Asset::cw20(api.addr_validate("token_addr")?, 67890u128),

    let msgs = assets.transfer_msgs(api.addr_validate("recipient_addr")?)?;

    Ok(Response::new().add_messages(msgs).add_attribute("assets_sent", assets.to_string()))

Use in messages

Asset and AssetList each comes with an unchecked counterpart which contains unverified addresses and/or denoms, and implements traits that allow them to be serialized into JSON, so that they can be directly used in Cosmos messages:

use cosmwasm_schema::cw_serde;
use cw_asset::AssetUnchecked;

pub enum ExecuteMsg {
    Deposit {
        asset: AssetUnchecked,

Although Asset and AssetList also implement the related traits, hence can also be used in messages, it is not recommended to do so; it is a good security practice to never trust addresses passed in by messages to be valid. Instead, also validate them yourselves:

use cosmwasm_std::{Api, StdResult};
use cw_asset::{Asset, AssetError, AssetUnchecked};

const ACCEPTED_DENOMS: &[&str] = &["uatom", "uosmo", "uluna"];

fn validate_deposit(api: &dyn Api, asset_unchecked: AssetUnchecked) -> Result<(), AssetError> {
    let asset: Asset = asset_unchecked.check(api, Some(ACCEPTED_DENOMS))?;


~129K SLoC