Logo

dev-resources.site

for different kinds of informations.

Setup Smart Contract Development with Foundry and Thirdweb

Published at
9/6/2022
Categories
tutorial
solidity
thirdweb
foundry
Author
aeither
Author
7 person written this
aeither
open
Setup Smart Contract Development with Foundry and Thirdweb

Intro

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.

Setup

Our first step is to download the repository of the starter
https://github.com/thirdweb-example/forge-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
@thirdweb-dev/=node_modules/@thirdweb-dev/
@openzeppelin=node_modules/@openzeppelin/
forge-std/=lib/forge-std/src/
ds-test/=lib/forge-std/lib/ds-test/src/
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

Deployment

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

https://book.getfoundry.sh/

https://github.com/thirdweb-example/forge-starter
https://github.com/thirdweb-dev/contracts
https://portal.thirdweb.com/extensions

https://thirdweb.com/deployer.thirdweb.eth/TokenERC20

foundry Article's
24 articles in total
Favicon
Mainnet Forking in Foundry
Favicon
Foundry tutorial para inciantes
Favicon
How to deploy smart contracts using Foundry
Favicon
The best way to import your private key in Foundry
Favicon
Streamline Your Smart Contract Development with Foundry
Favicon
Developer’s Guide to ERC-4337 #1 | Developing Simple Account
Favicon
How to write and compile smart contracts in Foundry
Favicon
How to Install Foundry on Windows/macOS/Linux
Favicon
Build a Multi-Payment DApp on Morph with Foundry
Favicon
How I Built a Decentralized Crowdfunding App with Foundry(incl. unit tests)
Favicon
Cómo desplegar y verificar un contrato inteligente en la blockchain de Mode usando Foundry
Favicon
How to Deploy and Verify a Smart Contract on Mode's Blockchain using Foundry
Favicon
Ethereum Development: Foundry or Hardhat
Favicon
Deploy Upgradeable Smart Contracts with Foundry and OpenZeppelin
Favicon
Foundry - chisel
Favicon
Introduction to smart contract development using Foundry
Favicon
Foundry Test : ERC721 SOL (Postmortem)
Favicon
Deploy a smart contract to an arbitrary address
Favicon
Installing foundry toolchain on windows.
Favicon
Setup Smart Contract Development with Foundry and Thirdweb
Favicon
Compiling and testing Vyper contract using Foundry
Favicon
Foundry – Solidity Tests, Fuzzing and so much more!
Favicon
Foundry Vs Hardhat
Favicon
使用Foundry,感受快,rust对写合约的支持

Featured ones: