Contracts

Stylus Minting Modules

You can now install rust based modules into a solidity based modular contract.

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.

  • Select Modular Contract for Stylus

    Navigate to the Modular Contracts section on Explore and select any token contract for your project.

  • 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.

  • 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:

    You can customize these modules via thirdweb CLI as described below.

Build with CLI

If you want to modify the contract code or publish a custom module, you can use the thirdweb CLI.

  • 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.

    npx thirdweb create-stylus
  • Modify logic

    In the src/lib.rs file you can modify the contract logic such as adding fees, gating logic, analytics events, and more.

  • Build & Test

    To build your project, run the following command:

    cargo stylus build
  • 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:

    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.

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

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

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

import { sendTransaction } from "thirdweb";
import { TransferableERC20 } from "thirdweb/modules";
const transaction = TransferableERC20.setTransferable({
contract,
enableTransfer: ...,
overrides: {
...
}
});
// Send the transaction
await sendTransaction({ transaction, account });

Resources