Skip to main content

Virtual balances

Query Messages

note

We will only go through the queries for this contract, as users are not allowed to execute any messages on the Virtual Balance contract directly. You can read about the Virtual balance architecture here

List of queries that can be performed on the Virtual Balance contract.

GetState

Queries the state returning the address of the router and admin of the contract.

pub enum QueryMsg {
    #[returns(GetStateResponse)]
    GetState {},
}
{"get_state"{}}

The query returns the following response:

#[cw_serde]
pub struct GetStateResponse {
pub state: State,
}
pub struct State {
pub router: String,
pub admin: Addr,
}
NameTypeDescription
routerStringThe contract address of the router that relays to and from this contract.
adminAddrThe contract address of the admin of the contract.

GetBalance

Queries the virtual balance of the specified user on the specified chain for the specified token.

pub enum QueryMsg {
 #[returns(GetBalanceResponse)]
 GetBalance { balance_key: BalanceKey },
}

pub struct BalanceKey {
    pub cross_chain_user: CrossChainUser,
    pub token_id: TokenId,
}
{
  "get_balance": {
    "balance_key": {
      "cross_chain_user": {
        "chain_uid": "chainC",
        "address": "comso1..."
      },
      "token_id": "token-id"
    }
  }
}
NameTypeDescription
balance_keyBalanceKeyThe key used to get the balance.

BalanceKey:

NameTypeDescription
cross_chain_userCrossChainUserThe user on the specified chain.
token_idTokenIdThe identifier of the token.

The query returns the following response:

pub struct GetBalanceResponse {
pub amount: Uint128,
}
NameDescription
amountThe amount of tokens in the specified user's balance.

GetUserBalances

Queries all the virtual balances for all tokens for the specified user on the specified chain.

pub enum QueryMsg {
    #[returns(GetUserBalancesResponse)]
    GetUserBalances { user: CrossChainUser },
}
{
  "get_user_balances": {
    "user": {
      "chain_uid": "chainA",
      "address": "nibi1..."
    }
  }
}
NameDescription
chain_uidThe unique Id of the chain we want to get the balances on.
addressAddress of the user we are getting the balances for.

The query returns the following response:

pub struct GetUserBalancesResponse {
pub balances: Vec<GetUserBalancesResponseItem>,
}

pub struct GetUserBalancesResponseItem {
pub amount: Uint128,
pub token_id: String,
}

NameDescription
amountThe amount of tokens in the specified user's balance.
token_idThe Id of the token the amount corresponds to.