This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "WIP: Modular contract documentation [DO NOT MERGE]" (#533)
- Loading branch information
1 parent
668f05c
commit 1fe09e5
Showing
130 changed files
with
582 additions
and
1,515 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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,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); | ||
} | ||
} | ||
``` | ||
|
||
``` | ||
``` |
File renamed without changes
File renamed without changes
2 changes: 0 additions & 2 deletions
2
...ular-contracts/modular-contracts/page.mdx → ...ontracts/build/modular-contracts/page.mdx
This file contains 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
2 changes: 1 addition & 1 deletion
2
...racts/overview/assets/extension-model.svg → ...build/overview/assets/extension-model.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,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. |
56 changes: 0 additions & 56 deletions
56
src/app/contracts/modular-contracts/core-contracts/erc-1155/page.mdx
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/app/contracts/modular-contracts/core-contracts/erc-20/page.mdx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.