5 releases (3 breaking)

0.26.0 Jan 7, 2025
0.24.1 Oct 25, 2024
0.24.1-beta.2 Oct 17, 2024
0.23.0 Jul 18, 2024
0.22.0 Jul 16, 2024

#935 in Magic Beans

Download history 11/week @ 2024-09-24 4/week @ 2024-10-01 4/week @ 2024-10-08 175/week @ 2024-10-15 182/week @ 2024-10-22 41/week @ 2024-10-29 25/week @ 2024-11-05 10/week @ 2024-11-12 25/week @ 2024-11-19 11/week @ 2024-11-26 14/week @ 2024-12-03 26/week @ 2024-12-10 21/week @ 2024-12-17 12/week @ 2024-12-24 6/week @ 2024-12-31 125/week @ 2025-01-07

168 downloads per month

LGPL-3.0 and GPL-3.0-or-later

28KB
560 lines

Abstract Standalone

This crate contains a StandaloneContract struct that can be used to interact with the abstract on-chain infrastructure.S

Usage

First, import the crate in your Cargo.toml.

[dependencies]
abstract-standalone = "<latest version>"

You can then define the contract's constant:

pub const CONTRACT_ID: &str = "my-namespace:my-contract";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

pub const MY_CONTRACT: MockStandaloneContract =
        MockStandaloneContract::new(CONTRACT_ID, VERSION, None);

Next, include the StandaloneInstantiateMsg struct in your contract's instantiate message. We'll need this data to instantiate the MY_CONTRACT state.

use abstract_standlone::StandaloneInstantiateMsg;

#[cosmwasm_schema::cw_serde]
pub struct InstantiateMsg {
    pub base: StandaloneInstantiateMsg,
    // .. Your custom fields here.
}

Then, use the StandaloneInstantiateMsg struct to instantiate the state.

#[cosmwasm_std::entry_point]
pub fn instantiate(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    msg: InstantiateMsg,
) -> Result<Response, MockError> {
    MY_CONTRACT.instantiate(deps, info, msg.base, true)?;

    // Your custom logic here.
}

Finally, you can use the MY_CONTRACT const to interact with the Abstract on-chain infrastructure through our APIs.

#[cosmwasm_std::entry_point]
pub fn execute(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    msg: ExecuteMsg,
) -> Result<Response, MockError> {

    // Example of using an Abstract API.
    let bank: Bank<StandaloneContract> = MY_CONTRACT.bank(deps.as_ref());
    let account_balance: Coin = bank_api.balance(&AssetEntry::new("abstract"))?;
    // ...

    Ok(MY_CONTRACT.response("mock_exec"))
}

Dependencies

~7–26MB
~305K SLoC