-
Notifications
You must be signed in to change notification settings - Fork 619
Stylus modules #8383
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
Merged
Merged
Stylus modules #8383
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7b09d75
Deploy and install stylus modules
kumaryash90 19378f5
changeset
kumaryash90 5343a41
compatibility
kumaryash90 1e16b99
enable stylus modular contracts in explore
kumaryash90 4bb0d43
show in explore, beta
kumaryash90 02bc9f0
cli templates for creating rust modules
kumaryash90 b75c9b3
Merge branch 'main' into yash/stylus-deploy-modules
kumaryash90 883c575
fix dynamic contract tests
kumaryash90 6e931b2
Merge branch 'main' of github.com:thirdweb-dev/js into yash/stylus-de…
kumaryash90 6bae339
Merge branch 'yash/stylus-deploy-modules' of github.com:thirdweb-dev/…
kumaryash90 26c090d
docs
kumaryash90 16fc56d
lint
kumaryash90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| deploy and install stylus modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
apps/portal/src/app/contracts/arbitrum-stylus/minting-modules/page.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { Step, Steps, createMetadata } from "@doc"; | ||
|
|
||
| export const metadata = createMetadata({ | ||
| title: "Stylus Minting Modules | thirdweb Documentation", | ||
| description: | ||
| "Customizable rust modules written for thirdweb's modular contracts", | ||
| image: { | ||
| title: "Stylus Minting Modules", | ||
| icon: "contracts", | ||
| }, | ||
| }); | ||
|
|
||
| # Stylus Minting Modules | ||
|
|
||
| You can now install rust based modules into a solidity based [modular contract](https://github.com/thirdweb-dev/modular-contracts/blob/dev/design-document.md). | ||
|
|
||
| This plug-n-play model also allows users to write their own custom minting logic in rust, taking advantage of Stylus' interoperability and gas savings. These modules work with existing router contracts and modules written in solidity. | ||
|
|
||
| ## Deploy through dashboard | ||
|
|
||
| Deploying a Modular Contract and installing modules is easy through the thirdweb dashboard and ideal when you don't want to modify any code on the contract. | ||
|
|
||
| <Steps> | ||
| <Step title="Select Modular Contract for Stylus"> | ||
|
|
||
| Navigate to the Modular Contracts section on Explore and select any token contract for your project. | ||
| </Step> | ||
|
|
||
| <Step title="Deploy Contract"> | ||
| Select Arbitrum Sepolia or any other Stylus-supported network, then select Deploy. Once you have deployed one of these contracts, the modules come pre-installed, both solidity and rust ones. | ||
| </Step> | ||
|
|
||
| <Step title="Edit Modules"> | ||
| If you wish to install a custom module, navigate to modules tab on your contract page. Enter the publisher address and select module from the dropdown, and click install. | ||
|
|
||
| You can uninstall a module from the same page. | ||
|
|
||
| Here's a list of prebuilt Rust / Stylus specific modules provided by thirdweb: | ||
| - [Mintable ERC20](https://thirdweb.com/0x6453a486d52e0EB6E79Ec4491038E2522a926936/StylusMintableERC20) | ||
| - [Transferable ERC20](https://thirdweb.com/0x6453a486d52e0EB6E79Ec4491038E2522a926936/StylusTransferableERC20) | ||
| - [Mintable ERC721](https://thirdweb.com/0x6453a486d52e0EB6E79Ec4491038E2522a926936/StylusMintableERC721) | ||
| - [Transferable ERC721](https://thirdweb.com/0x6453a486d52e0EB6E79Ec4491038E2522a926936/StylusTransferableERC721) | ||
| - [Mintable ERC1155](https://thirdweb.com/0x6453a486d52e0EB6E79Ec4491038E2522a926936/StylusMintableERC1155) | ||
| - [Transferable ERC1155](https://thirdweb.com/0x6453a486d52e0EB6E79Ec4491038E2522a926936/StylusTransferableERC1155) | ||
|
|
||
| You can customize these modules via thirdweb CLI as described below. | ||
|
|
||
| </Step> | ||
|
|
||
| </Steps> | ||
|
|
||
| ## Build with CLI | ||
|
|
||
| If you want to modify the contract code or publish a custom module, you can use the thirdweb CLI. | ||
|
|
||
| <Steps> | ||
| <Step title="Create a new Stylus module"> | ||
|
|
||
| In your CLI, run the following command to create a new directory with an template module. Select the module template from the list shown. | ||
|
|
||
| ```bash | ||
| npx thirdweb create-stylus | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Modify logic"> | ||
| In the `src/lib.rs` file you can modify the contract logic such as adding fees, gating logic, analytics events, and more. | ||
| </Step> | ||
|
|
||
| <Step title="Build & Test"> | ||
|
|
||
| To build your project, run the following command: | ||
|
|
||
| ```bash | ||
| cargo stylus build | ||
| ``` | ||
|
|
||
| </Step> | ||
|
|
||
| <Step title="Deploy or Publish Your Module"> | ||
| You can publish your module and install it to your modular contract. Publishing stores your module metadata in thirdweb’s on-chain registry so anyone (including you) can use that exact version later with a few clicks. | ||
|
|
||
| To publish your module, ensure you have your thirdweb secret key from your created project, then run the following command: | ||
|
|
||
| ```bash | ||
| npx thirdweb publish-stylus -k YOUR_TW_SECRET_KEY | ||
| ``` | ||
|
|
||
| Once published, the module is now available to install via thirdweb dashboard from the modules tab of your contract. | ||
| </Step> | ||
|
|
||
| </Steps> | ||
|
|
||
| ## Interacting with the Contract | ||
|
|
||
| Using the thirdweb SDKs, you can interact with your Stylus Modular contracts / modules to mint tokens, transfer ownership, and more. | ||
|
|
||
| The following describes how to interact with a ERC721 modular contract using thirdweb SDK. (Swap for ERC20 or ERC1155 variants as needed.) | ||
|
|
||
| ### Upload metadata | ||
|
|
||
| ```ts | ||
| import { BatchMetadataERC721 } from "thirdweb/modules"; | ||
|
|
||
| const transaction = BatchMetadataERC721.uploadMetadata({ | ||
| contract, | ||
| metadatas: [ | ||
| { name: "My NFT", description: "This is my NFT" }, | ||
| ], | ||
| }); | ||
|
|
||
| await sendTransaction({ | ||
| transaction, | ||
| account, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Mint with role | ||
|
|
||
| ```typescript | ||
| import { MintableERC721 } from "thirdweb/modules"; | ||
|
|
||
| const transaction = MintableERC721.mintWithRole({ | ||
| contract, | ||
| to: "0x...", // Address to mint tokens to | ||
| nfts: [ | ||
| { | ||
| name: "My NFT", | ||
| description: "This is my NFT", | ||
| image: "ipfs://...", | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| // Send the transaction | ||
| await sendTransaction({ transaction, account }); | ||
| ``` | ||
|
|
||
| ### Set transfer rules | ||
|
|
||
| ```ts | ||
| import { sendTransaction } from "thirdweb"; | ||
| import { TransferableERC20 } from "thirdweb/modules"; | ||
|
|
||
| const transaction = TransferableERC20.setTransferable({ | ||
| contract, | ||
| enableTransfer: ..., | ||
| overrides: { | ||
| ... | ||
| } | ||
| }); | ||
|
|
||
| // Send the transaction | ||
| await sendTransaction({ transaction, account }); | ||
| ``` | ||
|
|
||
| ### Resources | ||
|
|
||
| - [Modular Contracts Design Doc](https://github.com/thirdweb-dev/modular-contracts/blob/dev/design-document.md) | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.