Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Revert "WIP: Modular contract documentation [DO NOT MERGE]" (#533)
Browse files Browse the repository at this point in the history
Revert "WIP: Modular contract documentation [DO NOT MERGE] (#528)"

This reverts commit 668f05c.
  • Loading branch information
saminacodes authored Jul 27, 2024
1 parent 668f05c commit 1fe09e5
Show file tree
Hide file tree
Showing 130 changed files with 582 additions and 1,515 deletions.
Binary file removed bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"escape-string-regexp": "^5.0.0",
"flexsearch": "^0.7.43",
"github-slugger": "^2.0.0",
"lucide-react": "^0.416.0",
"lucide-react": "^0.286.0",
"next": "^14.2.3",
"nextjs-toploader": "^1.6.12",
"node-html-parser": "^6.1.13",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

186 changes: 186 additions & 0 deletions src/app/contracts/build/get-started/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
import { createMetadata } from "@doc";

export const metadata = createMetadata({
image: { title: "Get Started with thirdweb Solidity SDK", icon: "solidity" },
title: "Get Started with thirdweb Solidity SDK",
description:
"To get started with the Solidity SDK, run the following command to create a new project:",
});

# Getting Started

To get started with the Solidity SDK, run the following command to create a new project:

```bash
npx thirdweb create contract
```

Or, install the `contracts` package into your existing Solidity project:

<Tabs defaultValue="forge">

<TabsList>
<TabsTrigger value="forge">Forge</TabsTrigger>
<TabsTrigger value="hardhat">Hardhat</TabsTrigger>
</TabsList>

<TabsContent value="forge">
```bash
forge install https://github.com/thirdweb-dev/contracts
```
</TabsContent>
<TabsContent value="hardhat">
```bash
npm i @thirdweb-dev/contracts
```
</TabsContent>
</Tabs>

## Using the Solidity SDK

The Solidity SDK can be used to build new smart contracts _end-to-end_, or to add functionality to your own, existing smart contract using [extensions](/contracts/build/extensions).

All functions in the [base contracts](/contracts/build/base-contracts) and [extensions](/contracts/build/extensions) can be modified by [overriding them](/contracts/build/get-started#inheritance-and-overriding-functions).

### Using Base Contracts

The Solidity SDK includes [base contracts](/contracts/build/base-contracts) that are fully complete smart contracts that can be customized by overriding functions OR by adding extensions.

**1.** To start, import and inherit the base contract. You can find the list of all available base contracts [here](/contracts/build/base-contracts).

**2.** Base contracts expect certain constructor arguments to function as intended. Implement a constructor for your smart contract and pass the
appropriate values to a constructor for the base contract.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/base/ERC721Base.sol";
contract MyNFT is ERC721Base {
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {}
}
```

**3.** Now you're all set up! 🎉 Your smart contract now has all the [extensions](/contracts/build/extensions) provided by the [base contract](/contracts/build/base-contracts) it inherits and is ready to be [deployed](/contracts/deploy/overview) to any EVM blockchain of your choice.

### Using Extensions

Extensions are to be used via inheritance - your project's smart contract will inherit from them.

Additional [extensions](/contracts/build/extensions) can be added to existing smart contracts or to the [base contracts](/contracts/build/base-contracts) to add extra functionality and unlocking features in the SDKs and Dashboard.

**1.** To start, import and inherit the extension. You can find the list of all available extensions [here](/contracts/build/extensions).

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/base/ERC721Base.sol";
import "@thirdweb-dev/contracts/extension/Permissions.sol";
contract MyNFT is ERC721Base, Permissions {
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {}
}
```

**Note:**

- Some Extensions are **Abstract** and so require certain functions to be implemented\*.
- Some Extensions are **Interfaces** and so require **all** the functions to be implemented\*.

\*implement = write the logic for the function with a matching function signature (matching name, parameters, visibility and return type)

**2.** Use the functions provided by the Extension to change the behavior of your smart contract.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/base/ERC721Base.sol";
import "@thirdweb-dev/contracts/extension/Permissions.sol";
contract MyNFT is ERC721Base, Permissions {
bytes32 private constant MINTER_ROLE = keccak256("MINTER_ROLE");
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {}
/**
* `_canMint` is a function available in `ERC721Base`.
*
* It is called every time a wallet tries to mint NFTs on this
* contract, and lets you define the condition in which an
* attempt to mint NFTs should be permitted, or rejected.
*
* By default, `ERC721Base` only lets the contract's owner mint
* NFTs. Here, we override that functionality.
*
* We use the `Permissions` extension to specify that anyone holding
* "MINTER_ROLE" should be able to mint NFTs.
*/
function _canMint() internal view override returns (bool) {
return hasRole(MINTER_ROLE, msg.sender);
}
}
```

### Inheritance and Overriding Functions

Inheritance allows you to extend your smart contract's properties to include the parent contract's attributes and properties.
The inherited functions from this parent contract can be modified in the child contract via a process known as overriding.

Parent contract: Contract that the inheriting contract is inheriting from.

Child contract: The inheriting contract.

To override a function, to add your own custom logic, simply use the keyword `override` when declaring the function, making sure that the function signature matches.
To add the original logic from the parent contract, use the keyword `super`.

For example, the [`ERC721Base`](/contracts/build/base-contracts/erc-721/base) contract has an implementation of the function `mintTo`, I could instead override this function to add custom logic
and restrict this function in the `myNFT` contract to only allow 1 NFT per wallet:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/base/ERC721Base.sol";
import "@thirdweb-dev/contracts/extension/Permissions.sol";
contract MyNFT is ERC721Base, Permissions {
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {}
function mintTo(address _to, string memory _tokenURI) public override {
require(balanceOf(_to) < 1, "only 1 NFT per wallet!");
super.mintTo(_to, _tokenURI);
}
}
```

```
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# vim: ft=jsx

import { DocImage, Callout } from "@doc";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
import modularContractsAnalogyImage from "./assets/modular-contracts-analogy.png";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions src/app/contracts/build/overview/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { DocImage } from "@doc";
import extensinoModelImage from "./assets/extension-model.svg";
import { createMetadata } from "@doc";

export const metadata = createMetadata({
title: "thirdweb Solidity SDK",
description:
"Solidity SDK provides the tools needed to build custom smart contracts more efficiently by offering a set of pre-built base contracts and reusable components, better known as extensions.",
image: {
title: "thirdweb Solidity SDK",
icon: "solidity",
},
});

# Build (Solidity SDK)

**Build** or **Solidity SDK** provides the tools needed to build custom smart contracts more efficiently by offering a set of pre-built base contracts and reusable components, better known as extensions.

<DocImage src={extensinoModelImage} />

#### Features

- **Supports popular EIPs:** Effortlessly integrate common smart contract features and functionality from popular EIPs such as ERC-20, ERC-721, ERC-1155, permissions, metadata, and more.
- **Open Source:** The Solidity SDK is open-source and therefore available for any user to audit or contribute to the repository. [View the contracts repository.](https://github.com/thirdweb-dev/contracts)
- **Gas-optimized and audited base contracts:** Using base contracts provides a gas-optimized and audited foundation to build your projects.
- **Unlocked Management & Building Tools:** Each inherited extension unlocks easy-to-use functions in the contract interaction SDKs, custom admin dashboards, and tailored data feeds.

This file was deleted.

50 changes: 0 additions & 50 deletions src/app/contracts/modular-contracts/core-contracts/erc-20/page.mdx

This file was deleted.

Loading

0 comments on commit 1fe09e5

Please sign in to comment.