near-contract-tools

Helpful functions and macros for developing smart contracts on NEAR Protocol.

This package is a collection of common tools and patterns in NEAR smart contract development:

Not to be confused with near-contract-standards, which contains official implementations of standardized NEPs.

Example

Ownership

```rust use nearsdk::{ nearbindgen, AccountId, assertoneyocto, }; use nearcontracttools::{ impl_ownership, ownership::Ownership, };

[near_bindgen]

struct Contract { pub ownership: Ownership, }

impl_ownership!(Contract, ownership); ```

This creates a smart contract which exposes the Ownable trait to the blockchain:

rust pub trait Ownable { fn own_get_owner(&self) -> Option<AccountId>; fn own_get_proposed_owner(&self) -> Option<AccountId>; fn own_renounce_owner(&mut self); fn own_propose_owner(&mut self, account_id: Option<AccountId>); fn own_accept_owner(&mut self); }

Events

```rust use nearcontracttools::event::*; use nearcontracttools::Event; use serde::Serialize;

[derive(Serialize)]

pub struct Nep171NftMintData { pub ownerid: String, pub tokenids: Vec, }

[derive(Event, Serialize)]

[event(standard = "nep171", version = "1.0.0")]

[serde(untagged)]

pub enum Nep171 { #[event = "nft_mint"] NftMint(Vec), }

let myevent = Nep171::NftMint(vec![Nep171NftMintData { ownerid: "owner".tostring(), tokenids: vec!["token1".tostring(), "token2".tostring()], }]);

my_event.emit(); // Emits event to the blockchain ```

Authors