DEV Community

Giovanni Fu Lin
Giovanni Fu Lin

Posted on

Setup Smart Contract Development with Foundry and Thirdweb


In this guide, you are going to learn how to set up a starter smart contract with Foundry and ThirdWeb. Foundry provides the fastest way to test your smart contract with Solidity. On the other hand, Thirdweb3 provides extensions: a Solidity library of reusable and secure smart contracts. Once this contract is built, we can deploy it and get a dashboard that helps us interact with it. Last but not least, ThirdWeb allows us to create contracts and share them with the team or everyone.


Our first step is to download the repository of the starter

Install the dependencies

npm i @openzeppelin/contracts @openzeppelin/contracts-upgradeable

npm i @thirdweb-dev/contracts
Enter fullscreen mode Exit fullscreen mode
  • Refresh Visual studio code if it said that the contract does not exist when importing it.

Add to remappings in foundry.toml or create remappings.txt because vscode extension solidity has some issue finding remapping from foundry.toml for correct error highlight.

forge remappings
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode

Lets Create an initial example. ThirdWeb provides two types of extensions:

  • Base contracts that you can build upon.
  • Features for you to implement.
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.13;

import "@thirdweb-dev/contracts/token/TokenERC20.sol";

contract Contract is TokenERC20 {

constructor() {}

fallback() external payable {}

receive() external payable {}

function mintWithFee() public payable {

_mint(msg.sender, msg.value);


Enter fullscreen mode Exit fullscreen mode

Fallback and receive functions are executed when a non-existent function is called or there is no data supplied with the function call, respectively.

Create a test to make sure that everything works as expected.

// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.13;

import "forge-std/Test.sol";

import {Contract} from "src/Contract.sol";

contract ContractTest is Test {

Contract myContract;

function setUp() public {

myContract = new Contract();


function testExample() public {

myContract.mintWithWei{value: 1 wei}();

assertEq(myContract.balanceOf(address(this)), 1 wei);


Enter fullscreen mode Exit fullscreen mode


Run forge test to test it.
Run npm run deploy to deploy to Thirdweb Dashboard.
Run npm run release to upload the contract to your profile so that everyone can find it and use it.

Useful Links

Top comments (0)