Nois standard library

nois on crates.io nois on docs.rs

Use this library to integrate your app with the a nois proxy.

Storing the proxy address

```rust

[entry_point]

pub fn instantiate( deps: DepsMut, env: Env, _info: MessageInfo, msg: InstantiateMsg, ) -> Result { let noisproxyaddr = deps .api .addrvalidate(&msg.noisproxy) .maperr(|| ContractError::InvalidProxyAddress)?; NOISPROXY.save(deps.storage, &noisproxyaddr)?; Ok(Response::new() .addattribute("action", "instantiate") .addattribute("noisproxy", msg.noisproxy)) } ```

Sending a request

```rust use nois::ProxyExecuteMsg;

pub fn executeestimatepi( deps: DepsMut, env: Env, _info: MessageInfo, jobid: String, ) -> Result { let noisproxy = NOISPROXY.load(deps.storage)?; // Nois proxy address stored in init

let res = Response::new().add_message(WasmMsg::Execute {
    contract_addr: nois_proxy.into(),
    msg: to_binary(&ProxyExecuteMsg::GetNextRandomness { job_id })?,
    funds: vec![],
});
Ok(res)

} ```

Processing the callback

Create a ExecuteMsg enum case called Receive

```rust use cosmwasmschema::{cwserde, QueryResponses};

use nois::NoisCallback;

[cw_serde]

pub enum ExecuteMsg { // ...

Receive {
    callback: NoisCallback,
},

} ```

and use it:

```rust

[entry_point]

pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { // ...

    ExecuteMsg::Receive { callback } => execute_receive(deps, env, info, callback),
}

}

// ...

pub fn executereceive( deps: DepsMut, _env: Env, _info: MessageInfo, callback: NoisCallback, ) -> Result { let proxy = NOISPROXY.load(deps.storage)?; ensure_eq!(info.sender, proxy, ContractError::UnauthorizedReceive);

let NoisCallback { job_id, randomness } = callback;
let randomness: [u8; 32] = randomness
    .to_array()
    .map_err(|_| ContractError::InvalidRandomness)?;

// use randomness 🎉

} ```