Cookbook.dev
Cookbook.dev is an open-source smart contract registry where developers can find solidity primitives, libraries, and smart contracts for protocols.
In this tutorial, we'll walk through searching for a protocol on Cookbook and deploying it to Linea using Cookbook's no-code deploy and using Cookbook with Remix, Hardhat and Foundry.
Prerequisitesβ
Before you begin, ensure you've:
- Set up your wallet
- Funded your wallet with Linea ETH on either the testnet or mainnet
Search Cookbook's Smart Contract Registryβ
Navigate to cookbook.dev/chains/Linea and explore Protocols on Linea, or search for specific smart contracts in the search bar.
To learn about a smart contract on Cookbook, select the protocol, and select Expand
. This opens the code alongside ChefGPT, Cookbook's AI Solidity assistant.
Highlight selections of the code and press Analyze Snippet to get more information about the smart contract code you're looking at, or ask ChefGPT questions about Linea, solidity, or your smart contract.
Import any Smart Contract Code into Cookbookβ
Import verified smart contract code into Cookbook to fork, learn about, or build with by inputting any smart contract address into the Cookbook search bar.
No-code Deploy your Smart Contract to Linea with Cookbookβ
Choose No-Code Deploy on select (usually simpler) smart contracts on Cookbook.
Connect your Metamask Wallet to Cookbook.dev.
Set your smart contract arguments within the Cookbook UI (if applicable).
Select Linea or tLinea (Linea Testnet) under Pick Chain.
Select Deploy and pay the network fee.
Manage your deployed smart contract under My Dashboard in Cookbook.
Deploy your Smart Contract to Linea with Remixβ
Method #1 - Using the Cookbook.dev Website and Opening in Remixβ
On a smart contract or protocol page in Cookbook, select the Open in Remix option. Your smart contract will automatically be opened in a new Remix workspace.
Click the "Open in Remix" button above to actually open the smart contract code in the Remix IDE!
Compile your smart contract within Remix. Most contracts opened with Cookbook will automatically compile within Remix.
Once compiled, deploy the smart contract in Remix.
Connect your Metamask wallet with Linea Goerli or Linea mainnet by selecting injected provider - Metamask Wallet in the environments tab within the deploy screen.
Once deployed, we can interact with our smart contract within Remix.
Method #2 - Using the Cookbook Remix Plug-in within the Remix IDEβ
Go to Remix.Ethereum.org
Add The Cookbook Plugin to Remix by clicking the Chef Hat Logo under Featured Plugins on the Remix Homepage.
Alternatively, search Cookbook and select Activate in the Remix Plugin Manager.
Search for any protocol or smart contract and click the search result to import the smart contract code into Remix.
Cookbook's AI solidity co-pilot, ChefGPT, is available within the Remix plugin to answer questions about Linea, Solidity, or the smart contract you're working with.
Compile and deploy the smart contract as described in Method 1 above.
Deploy your Smart Contract to Linea with Hardhatβ
After finding the smart contract or protocol you want to work with in Cookbook, select the Download Source option and select Hardhat to download the contract boilerplate. For this guide, we'll use Cookbook's Simple ERC-20 Token Smart Contract.
To install the required packages and dependencies, run
npm install
To compile your smart contract, run
npx hardhat compile
Add arguments to the constructorArgs
array in the deploy.js
file in the scripts
folder and save. If you do not need any arguments please leave the array empty.
Deploy To Lineaβ
- Testnet
- Mainnet
In your .env.example
file, add your Infura Linea Goerli API key and add your wallet private key. Afterward change the name of the file to .env and create a gitignore to ignore your .env file.
In the hardhat.config.js
file, uncomment out the example code
const INFURA_API_KEY_LINEA_GOERLI = process.env.INFURA_API_KEY_LINEA_GOERLI;
and uncomment out
const PRIVATE_KEY = process.env.PRIVATE_KEY;
and then uncomment out
lineaGoerli: {
url: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY_LINEA_GOERLI}`,
accounts: [PRIVATE_KEY],
},
To deploy your smart contract to the Linea testnet, run
npx hardhat run --network (lineaGoerli) scripts/deploy.js
Hardhat will return the deployed smart contract address in your terminal. View and verify your smart contract on the Linea Goerli Block Explorer.
In your .env.example
file, add your Infura Linea API key and add your wallet private key. Afterward change the name of the file to .env and create a gitignore to ignore your .env file.
Add
INFURA_API_KEY_LINEA = "<YOUR API KEY HERE>"
In the hardhat.config.js
file, add
const INFURA_API_KEY_LINEA = process.env.INFURA_API_KEY_LINEA;
and uncomment out
const PRIVATE_KEY = process.env.PRIVATE_KEY;
and then add
linea: {
url: `https://linea.infura.io/v3/${INFURA_API_KEY_LINEA}`,
accounts: [PRIVATE_KEY],
},
To deploy your smart contract to the Linea testnet, run
npx hardhat run --network (linea) scripts/deploy.js
Hardhat will return the deployed smart contract address in your terminal. View and verify your smart contract on the Linea Block Explorer.
Deploy your Smart Contract to Linea with Foundryβ
After finding the smart contract or protocol you want to work with in Cookbook, select the Download Source option and select Foundry to download the contract boilerplate.For this guide, we'll use Cookbook's Simple ERC-20 Token Smart Contract.
Before you can use Foundry, you need to install Rust, a programming language required to run Foundry. Follow the installation instructions provided here.
Once Rust is installed, you can install Foundry. Follow the installation instructions provided here.
To build your contracts, Run
forge build
If you encounter a "stack too deep" error, try running the following command instead
forge build --via
In the scripts folder, uncomment all the code in the contract.s.sol
file. Replace "ARG1"
, "ARG2"
, 2000
with your Token Name
, Token Symbol
and desired Token Quantity
where you see the code below
FixedToken _contract = new FixedToken("ARG1", "ARG2", 2000);
Before deploying your contracts, populate the .env
file with your Linea Goerli RPC URL, followed by your Metamask wallet private key and your Etherscan API key token values. Then, run the following command to define your environment variables globally
source .env
add "0x" before your private key string in the .env
file
Deploy your contracts with the following command
forge script script/contract.s.sol:ContractScript --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv
Your contract will be verified on the Linea Goerli explorer automatically upon deployment. You can manage and interact with your newly deployed smart contract in the Linea Goerli block explorer.
The given tests in the contract.t.sol file are only examples, please generate your own
Further guidance
For more information on using Cookbook to find, learn about or build with smart contracts, check out the following resources: