This project is built using Foundry. For more information, visit the docs here
The provided Solidity contracts are intended solely for educational purposes and are not warranted for any specific use. They have not been audited and may contain vulnerabilities, hence should not be deployed in production environments. Users are advised to seek professional review and conduct a comprehensive security audit before any real-world application to mitigate risks of financial loss or other consequences. The author(s) disclaim all liability for any damages arising from the use of these contracts. Use at your own risk, acknowledging the inherent risks of smart contract technology on the blockchain.
Below is a diagram illustrating the architecture of the project.
This repository contains a sample BuyMeACoffee.sol contract which allows the user to buy the owner a coffee with 0.001 ether. Along with that the user can send the owner a memo.
It also contains a sample implementation (CustomERC1155.sol) of ERC1155 using openzeppelin's ERC1155 contract
Contract that allows a user to mint a ERC721A either from a allowlist or from a public mint. This is useful for mints where you want to allow specified users to have early access and (optionally) a lower mint price. After your defined allowlist window ends, the public mint will begin immediately. This contract uses ERC721A as base to allow for more efficient minting of multiple NFTs in a single transaction.
It also makes use of the following utility libraries for allowlist proof verification:
- solady MerkleProofLib: To verify proofs when minting.
- murky: To easily generate merkle roots and proofs in unit tests.
Deploy Instructions:
A deploy script AllowlistNFT.s.sol is provided. Please be sure to update all of the constructor arguments before deploying:
name: The name of your NFT collection.ticker: The ticker of your NFT collection.allowlistRoot: The allowlist root generated for your allowlisted addresses. For information on generating merkle roots for allowlists, you can read about this in-depth guide heremaxSupply: The maximum number of NFTs in your collection.price: The price of a public mint.allowlistPrice: The price of a allowlist mint.allowlistOpen: The timestamp in which allowlist mint begins.allowlistClose: The timestamp in which allowlist mint ends. Note: Public mint will begin immediately afterallowlistClose.maxAllowlistMint: The maximum number of NFTs a allowlisted address can allowlist mint.maxPublicMint: The maximum number of NFTs an address can public mint.uri: The base URI of your NFT. This is your IPFS hash.
.
├── foundry.toml
├── script
│ └── BuyMeACoffee.s.sol
│ └── CustomERC155.s.sol
│ └── AllowlistNFT.s.sol
├── src
│ └── BuyMeACoffee.sol
│ └── CustomERC155.sol
│ └── AllowlistNFT.sol
└── test
└── BuyMeACoffee.t.sol
└── CustomERC155.t.sol
└── AllowlistNFT.t.sol
- You can configure Foundry's behavior using foundry.toml.
- The default directory for contracts is src/.
- The default directory for tests is test/
- The default directory for writing scripts is script/
Install foundry using
curl -L https://foundry.paradigm.xyz | bash
foundryupFollow the instructions of foundryup to completely setup foundry
forge installforge buildforge testYou will need to install genhtml to generate html reports (brew install lcov for osx).
forge coverage --report lcov && genhtml -o report --branch-coverage lcov.infoforge fmtOpen .env file.
PRIVATE_KEY is your private wallet key. Make sure to prefix it by "0x" to convert to a hex string.
BLOCK_EXPLORER_API_KEY is your API Key from basescan.org for Base Sepolia
source .env
forge script script/BuyMeACoffee.s.sol:BuyMeACoffeeScript --broadcast --verify --rpc-url base_sepoliaNote: The above command will print the address of your contract and a link to the block explorer. Click on the block explorer link to verify whether your contract has been deployed or not
forge script script/DeployBaseFunding.s.sol:DeployBaseFunding --broadcast --rpc-url $RPC_URL --verify --etherscan-api-key $BLOCK_EXPLORER_API_KEY
[⠒] Compiling... No files changed, compilation skipped Script ran successfully.
== Logs == EducationFunding contract deployed at: 0x396F44b7bCe96ce44A7967Ac11Fe3712c2B03281
==========================
Chain 11155111
Estimated gas price: 52.658906228 gwei
Estimated total gas used for script: 1555330
Estimated amount required: 0.08190197662359524 ETH
==========================
Transactions saved to: /Users/s/girls-hacks /based-funding/contracts/broadcast/DeployBaseFunding.s.sol/11155111/run-latest.json
Sensitive values saved to: /Users/s/girls-hacks /based-funding/contracts/cache/DeployBaseFunding.s.sol/11155111/run-latest.json
Forge runs your solidity script. In that script it tries to broadcast the transaction. It writes it back into the broadcast folder in a run-latest.json file.
To extract the abi of your contract, you can go to out/BuyMeACoffee.sol/BuyMeACoffee.json and copy the value corresponding to the abi key
-
To deploy your own contract create a new
.solfile inside thecontracts/srcfolder, similar toBuyMeACoffee.sol -
Format and build your contracts using
forge fmtandforge buildrespectively. -
Write some tests by creating a test file inside
contracts/testfolder, similar toBuyMeACoffee.t.sol. Run the test usingforge test -
Write a deployment script inside
contracts/script, similar toBuyMeACoffee.s.sol -
Create a
.envfile using the.env.examplefile provided in your contracts folder and add your private key. Make sure to add a0xin front of your key to convert it to a hex string. -
Deploy your contract using the following commands:
source .env forge script script/YOUR_SCRIPT.s.sol:YOUR_SCRIPT --broadcast --rpc-url base_sepoliaNote: To deploy on a different network, simply add the specific RPC endpoint within the
[rpc_endpoints]section found in thefoundry.tomlfile. -
To extract the
abiof your contract, you can go toout/YOUR_CONTRACT.sol/YOUR_CONTRACT.jsonand copy the value corresponding to theabikey
Initially, building on a local node can offer numerous benefits, including:
- The ability to add debug statements.
- The capability to fork a chain at a particular block, enabling the detection of reasons behind specific behaviors.
- The absence of the need for testnet/mainnet funds.
- Faster testing, as only your node is responsible for consensus.
You can deploy your contracts to local node for faster testing as follows:
make local-nodeTo deploy the contract:
-
Make sure to delete the following lines from
foundry.tomlbecause locally we dont have a block explorer[etherscan] "${NETWORK}"={key="${BLOCK_EXPLORER_API_KEY}"} -
Create a
.envfile using the.env.examplefile provided in your contracts folder and add one the private keys printed on your terminal when you ranmake local-node. Also update theRPC_URLtohttp://127.0.0.1:8545, this will make sure your contracts are deployed locally -
Deploy the sample contract using:
source .env forge script script/LocalContract.s.sol:LocalContractScript --broadcast --rpc-url ${RPC_URL}
You can observe that the console2 library facilitates the addition of console logs in the contract, which would not have been possible if you were deploying to a testnet or mainnet.
If you would like to contribute to contracts folder, follow the given steps for setup
Install foundry using
curl -L https://foundry.paradigm.xyz | bash
foundryupFollow the instructions of foundryup to completely setup foundry
Run the following commands inside the contracts folder:
forge install
forge buildYou should be good to go :) Thank you for the support ❤️




