Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use openbrush #120

Merged
merged 3 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/getting-started/openbrush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Use OpenBrush
slug: /getting-started/use-openbrush
---

[OpenBrush] is a library for smart contract development on ink! mainatined by the [Brushfam](https://brushfam.io) team. OpenBrush is to ink! what OpenZeppellin is to Solidity.

It provides standard contracts based on [PSPs], as well as useful contracts and Rust macros to help you build ink! smart contracts.

Using OpenBrush is simple, you will only add the dependency to your `Cargo.toml` file. Here is an [example](https://docs.openbrush.io/smart-contracts/overview) of how to do it.

### Why use OpenBrush?

- To make contracts **interoperable** to do **safe** cross-contracts calls (by having the same function's signature among every contract)
- To ensure the usage of [Polkadot Standards Proposals][PSPs]
- To ensure the usage of the **latest and most secure** implementation
- Useful contracts that provide custom logic to be implemented in contracts
- To **save time** by not writing boilerplate code
- Useful features which can simplify development

### Which standard tokens and useful contracts does it provide?

- **PSP22** - Fungible Token (*ERC20 equivalent*) with extensions
- **PSP34** - Non-Fungible Token (*ERC721 equivalent*) with extensions
- **PSP37**: *ERC1155 equivalent* with extensions
- **Ownable** Restrict access to action for non-owners
- **Access Control**: Define a set of roles and restrict access to an action by roles
- **Reentrancy Guard**: Prevent reentrant calls to a function
- **Pausable**: Pause/Unpause the contract to disable/enable some operations
- **Timelock Controller**: Execute transactions with some delay
- **Payment Splitter**: Split the amount of native tokens between participants

### Generic Trait Implementation

More importantly, OpenBrush adds support for generic Trait implementation so you can split Trait and Impls into different files, which will increase the readability and maintainability of your smart-contract code base (see detailed description [here](https://github.com/727-Ventures/openbrush-contracts/blob/main/docs/docs/smart-contracts/example/setup_project.md))

### Wrapper around Traits

Defining a Trait definition is sufficient (a contract that implements that Trait is not needed anymore) to call methods of that Trait from some contract in the network (do a cross contract call). It makes cross-contract calls easier.

### Documentation

- [OpenBrush Github repo](https://github.com/727-Ventures/openbrush-contracts)
- [Official Docs](https://docs.openbrush.io/)
- [OpenBrush website](https://openbrush.io/)
- [Substrate Seminar (Youtube)](https://www.youtube.com/watch?v=I5OFGNVvzOc)
- [How to use modifiers](https://medium.com/supercolony/how-to-use-modifiers-for-ink-smart-contracts-using-openbrush-7a9e53ba1c76)

## Typechain-Polkadot

Another tool essential for ink! smart contracts development is [Typechain-Polkadot](https://github.com/727-Ventures/typechain-polkadot).

Typechain-Polkadot is used to generate Typescript wrappers around your smart-contract, which can be used in UI or in integration tests of your ink! smart contracts. It uses polkadot-api under the hood, but is especially useful because all calls and queries are typed, therefore the chance of getting some error during a call is mitigated.

## Sol2Ink

[Sol2Ink](https://github.com/727-Ventures/sol2ink) is a useful tool which can help you migrating from Solidity to ink! You will only pass the Solidity code of your smart contract to Sol2Ink and get the ink! contract in return. You can also use Sol2Ink to learn the differences between Solidity and ink! code and use it to help you learning to create ink! smart contracts.

[OpenBrush]: https://github.com/727-Ventures/openbrush-contracts
[PSPs]: https://github.com/w3f/PSPs
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'Getting started': [
'getting-started/setup',
'getting-started/creating',
'getting-started/openbrush',
'getting-started/compiling',
'getting-started/running',
'getting-started/deploying',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Use OpenBrush
slug: /getting-started/use-openbrush
---

[OpenBrush] is a library for smart contract development on ink! mainatined by the [Brushfam](https://brushfam.io) team. OpenBrush is to ink! what OpenZeppellin is to Solidity.

It provides standard contracts based on [PSPs], as well as useful contracts and Rust macros to help you build ink! smart contracts.

Using OpenBrush is simple, you will only add the dependency to your `Cargo.toml` file. Here is an [example](https://docs.openbrush.io/smart-contracts/overview) of how to do it.

### Why use OpenBrush?

- To make contracts **interoperable** to do **safe** cross-contracts calls (by having the same function's signature among every contract)
- To ensure the usage of [Polkadot Standards Proposals][PSPs]
- To ensure the usage of the **latest and most secure** implementation
- Useful contracts that provide custom logic to be implemented in contracts
- To **save time** by not writing boilerplate code
- Useful features which can simplify development

### Which standard tokens and useful contracts does it provide?

- **PSP22** - Fungible Token (*ERC20 equivalent*) with extensions
- **PSP34** - Non-Fungible Token (*ERC721 equivalent*) with extensions
- **PSP37**: *ERC1155 equivalent* with extensions
- **Ownable** Restrict access to action for non-owners
- **Access Control**: Define a set of roles and restrict access to an action by roles
- **Reentrancy Guard**: Prevent reentrant calls to a function
- **Pausable**: Pause/Unpause the contract to disable/enable some operations
- **Timelock Controller**: Execute transactions with some delay
- **Payment Splitter**: Split the amount of native tokens between participants

### Generic Trait Implementation

More importantly, OpenBrush adds support for generic Trait implementation so you can split Trait and Impls into different files, which will increase the readability and maintainability of your smart-contract code base (see detailed description [here](https://github.com/727-Ventures/openbrush-contracts/blob/main/docs/docs/smart-contracts/example/setup_project.md))

### Wrapper around Traits

Defining a Trait definition is sufficient (a contract that implements that Trait is not needed anymore) to call methods of that Trait from some contract in the network (do a cross contract call). It makes cross-contract calls easier.

### Documentation

- [OpenBrush Github repo](https://github.com/727-Ventures/openbrush-contracts)
- [Official Docs](https://docs.openbrush.io/)
- [OpenBrush website](https://openbrush.io/)
- [Substrate Seminar (Youtube)](https://www.youtube.com/watch?v=I5OFGNVvzOc)
- [How to use modifiers](https://medium.com/supercolony/how-to-use-modifiers-for-ink-smart-contracts-using-openbrush-7a9e53ba1c76)

## Typechain-Polkadot

Another tool essential for ink! smart contracts development is [Typechain-Polkadot](https://github.com/727-Ventures/typechain-polkadot).

Typechain-Polkadot is used to generate Typescript wrappers around your smart-contract, which can be used in UI or in integration tests of your ink! smart contracts. It uses polkadot-api under the hood, but is especially useful because all calls and queries are typed, therefore the chance of getting some error during a call is mitigated.

## Sol2Ink

[Sol2Ink](https://github.com/727-Ventures/sol2ink) is a useful tool which can help you migrating from Solidity to ink! You will only pass the Solidity code of your smart contract to Sol2Ink and get the ink! contract in return. You can also use Sol2Ink to learn the differences between Solidity and ink! code and use it to help you learning to create ink! smart contracts.

### Questions?

If you have any questions about how to use any of these tools, or just about the ink! smart contracts in general, you can join the [Brushfam element channel](https://matrix.to/#/!utTuYglskDvqRRMQta:matrix.org?via=matrix.org&via=t2bot.io&via=web3.foundation) or ask a question on the [Substrate Stack Exchange](https://substrate.stackexchange.com/).

[OpenBrush]: https://github.com/727-Ventures/openbrush-contracts
[PSPs]: https://github.com/w3f/PSPs
1 change: 1 addition & 0 deletions versioned_sidebars/version-4.0.0-alpha.1-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"Getting started": [
"getting-started/setup",
"getting-started/creating",
"getting-started/openbrush",
"getting-started/compiling",
"getting-started/running",
"getting-started/deploying",
Expand Down