Crates.io | openbrush |
lib.rs | openbrush |
version | 3.2.0 |
source | src |
created_at | 2022-05-27 23:23:24.137502 |
updated_at | 2023-09-15 09:28:20.34127 |
description | OpenBrush library for smart contract development on ink!. |
homepage | https://727.ventures |
repository | https://github.com/727-Ventures/openbrush-contracts |
max_upload_size | |
id | 595369 |
size | 17,632 |
OpenBrush is maintained by the Brushfam team, and was created to make ink! development faster, safer and easier. We plan to integrate most of the features OpenBrush into ink!. OpenBrush provides documentation with FAQ section.
If you have any questions regarding OpenBrush, you can join the Brushfam Element channel to find your answers and meet other ink! smart contracts developers, or ask questions regarding ink! development on Element, Discord, or Telegram OpenBrush channels by the links above.
OpenBrush is a library for smart contract development on ink!.
Why use this library?
Which Standard tokens & useful contracts does it provide?
You can provide a default implementation in the traits method and have internal functions.
You can use the ink! trait as a native rust trait with several restrictions regarding
external functions(functions marked #[ink(message)]
).
#[openbrush::trait_definition]
pub trait Governance: AccessControl {
#[ink(message)]
fn execute(&mut self, transaction: Transaction) -> Result<(), GovernanceError> {
self.internal_execute(transaction)
}
fn internal_execute(&mut self, transaction: Transaction) -> Result<(), GovernanceError> {
...
}
}
Solidity smart contracts provides modifiers to restrain function call to certain pre-defined parameters. OpenBrush provides attribute macros to use standardised modifiers. You can use our useful contracts to use as modifiers, or define your own modifiers.
// Before execution of `mint` method, `only_owner` should verify that caller is the owner.
#[ink(message)]
#[modifiers(only_owner)]
fn mint(&mut self, ids_amounts: Vec<(Id, Balance)>) -> Result<(), PSP1155Error> {
self._mint_to(Self::env().caller(), ids_amounts)
}
You are enough to have a trait definition (you don't need directly a contract that implements that trait) to call methods of that trait from some contract in the network (do a cross contract call).
// Somewhere defined trait
#[openbrush::trait_definition]
pub trait Trait1 {
#[ink(message)]
fn foo(&mut self) -> bool;
}
// You can create wrapper in the place where you defined the trait
// Or if you import **everything** from the file where you define trait
#[openbrush::wrapper]
type Trait1Ref = dyn Trait1;
{
// It should be `AccountId` of contract in the network that implements `Trait1` trait
let callee: openbrush::traits::AccountId = [1; 32].into();
// This code will execute a cross contract call to `callee` contract
let result_of_foo: bool = Trait1Ref::foo(&callee);
}
Note: The trait should be defined with
openbrush::trait_definition
. The callee contract should implement that trait.
test_utils
to simplify unit testing of you code.traits
that provides some additional
functionality for your code.Not sure where to start? Use the interactive generator to bootstrap your contract and learn about the components offered in OpenBrush.
Events are not supported currently due to how ink! currently handles them.
The identifiers of events must be based on the name of the trait. At the moment, ink! doesn't support it,
but it must be fixed with this issue.
OpenBrush participates in the Web3 Grants, you can find the roadmap here
token
and access
folders.openbrush::contract
macro to consume all openbrush's stuff before ink!.openbrush::trait_definition
which stores definition of trait and allow to use it in openbrush::contract
macro.impl_trait!
macro which reuse internal implementation in external impl section.panic!
and assert!
).Ownable
+ ERC1155
example.impl_trait!
macro add support of default implementation in external trait definition.PSP34Enumerable
.Proxy
pattern.Diamond
standard.openbrush
into crates.ioAccessControlEnumerable
.PSP37Enumerable
.AssetChainExtension
to work with asset-pallet
.PSP22
via AssetChainExtension
.UniquesChainExtension
to work with uniques-pallet
.PSP34
via UniquesChainExtension
.To work with project you need to install ink! toolchain and NodeJS's dependencies.
yarn
command$ yarn build
If you want to build in release mode, you can use this command
$ yarn build:release
You can run unit tests by RUSTFLAGS="-D warnings" cargo +nightly test --workspace --features test-all -- --test-threads=10
command from the root of the directory.
To run integration test you need to start the node with contract-pallet.
After you can run tests by npm run test
command. It will build all contracts required for integration tests and run them.
Contracts in this repository have not yet been audited and contain several vulnerabilities due to the specific of the ink!. We know about them and will fix them with a new versions of ink!. ink! will have soon several major changes, so it does not make sense to audit it now. ink! is not ready for production at the moment. It requires resolving some issues.
After that, we plan to do an audit.
OpenBrush is released under the MIT License.