# BitBadges bindings for CosmWasm

This crate provides the custom bindings that are used to communicate with the custom modules (x/badges) on the BitBadges network from a CosmWasm smart contract.

# Installation Add the crate to your smart contract's' Cargo.toml toml [dependencies] bitbadges-cosmwasm = { version = "X.X.X" }

# Exposed bindings This crate, as of now, exports binding only for the x/badges module. In the future, more custom binding will be added.

Creating Messages

NOTE: The BitBadges bindings do not cover messages that have already been implemented by the CosmWasm team, such as staking-related messages and fundamental ones like MsgSend. ​ You may want your contract to perform messages such as MintBadge and RegisterAddresses operations at the end of its execution. To do this, create a message using the predefined functions: ​ - create_register_addresses_msg - ...

And add it to your response, like below ​ ```rust use cosmwasmstd::CosmosMsg; use bitbadgescosmwasm::{createregisteraddressesmsg}; ​ ... ​ pub fn executemsgregisteraddresses( deps: DepsMut, _env: Env, _info: MessageInfo, addressestoregister: Vec, ) -> StdResult> { let msg = createregisteraddressesmsg(addressestoregister);

Ok(Response::new().add_message(msg))

} ```

Querying

​ In order to use the query functions enabled by the bindings, create a BitBadgesQuerier instance within your contract logic -- in either init() or query() entrypoints. You can access all the enabled queries through this object. ​ ```rust // src/contract.rs use bitbadgescosmwasm::{ BitBadgesQuerier }; ​ ... ​pub fn querycollection(deps: Deps, id: u64) -> StdResult { let querier = BitBadgesQuerier::new(&deps.querier); let res: BadgeCollection = querier.query_collection(id)?;

Ok(res)

}

```

Example

Please consult the example smart contracts in /contracts - there you can see an example how to issue a transaction or make a query from the smart contract to the custom module. You can upload it and interact with it (and through it - with the bitbadges chain) with the following steps. This assumes you have a local bitbadges chain running.

```bash clonedDir='path/to/the/test/smart/contract/binary' bitbadgeschaind tx wasm store $clonedDir/bindings_tester.wasm --from=

--chain-id= --gas=auto -y INIT='{}'

Find the codeid of your stored contract (in the rawlog of output of the previous command or can query with bitbadgeschaind query wasm list-code)

bitbadgeschaind tx wasm instantiate yourcodeid $INIT --from=

--label="your_label" --chain-id= --gas=auto -y TESTER=$(bitbadgeschaind query wasm list-contract-by-code $CODE --output json | jq -r '.contracts[-1]') echo $TESTER

NOTE: sender field in the queries should be the address of your contract, in this case - $TESTER

issueDenom

NOTE: schema is optional field

NOTE: we convert to camelCase which should be used here

msgDetails='{ "registerAddressesMsg": { "addressesToRegister": [ "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl" ] } }' bitbadgeschaind tx wasm execute $TESTER $msgDetails --from=

--chain-id= --gas=auto -y ```

Acknowledgements

This repository was forked form the Cudos cosmwasm bindings. We would like to thank the Cudos team for their work on this project.