Cookbook.dev
Cookbook.dev is an open-source smart contract registry where developers can find solidity primitives, libraries, and smart contracts for protocols. It provides an easy and fast way to develop smart contracts by integrating with a variety of blockchain-native developer tools.
Here, 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:
- Set up your wallet
- Fund 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 smart contract code into Cookbook​
Import verified smart contract code into Cookbook by entering any smart contract address into the Cookbook search bar to fork, learn about, or build with.
Deploy a smart contract without coding​
Choose No-Code Deploy on select (usually simpler) smart contracts on Cookbook.
-
Connect your MetaMask Wallet to Cookbook.dev.
-
Set your smart contract arguments in 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 using Remix​
Method 1 - Use the Cookbook.dev website and open 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.
Select Compile to compile your smart contract in Remix. Most contracts opened with Cookbook will automatically compile within Remix.
Refer to the Remix instructions for more information on how to compile and deploy smart contracts in the Remix IDE.
Method 2 - Use the Cookbook Remix plug-in within the Remix IDE​
-
Go to Remix.Ethereum.org website.
-
Add the Cookbook Plugin to Remix by clicking the Cookbook 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 the Remix instructions.
Deploy your smart contract 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 example, we'll use Cookbook's Simple ERC-20 Token Smart Contract.
Compile the smart contract​
In the project folder, install the required packages and dependencies:
npm install
Then, compile the smart contract:
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, leave the array empty.
Deploy the smart contract​
- Linea Goerli
- Linea Sepolia
- Mainnet
-
In the
.env
file, add your Infura Linea Goerli API key and add your wallet private key. -
In the
hardhat.config.js
file, uncomment the following code:const INFURA_API_KEY_LINEA_GOERLI = process.env.INFURA_API_KEY_LINEA_GOERLI;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
lineaGoerli: {
url: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY_LINEA_GOERLI}`,
accounts: [PRIVATE_KEY],
}, -
Deploy the smart contract to the Linea Goerli testnet:
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
file, add your Infura Linea API key and add your wallet private key.INFURA_API_KEY_LINEA_SEPOLIA = "<YOUR API KEY HERE>"
WALLET_PRIVATE_KEY = "<YOUR PRIVATE KEY HERE>" -
In the
hardhat.config.js
file, add the following lines:const INFURA_API_KEY_LINEA_SEPOLIA = process.env.INFURA_API_KEY_LINEA;
lineaSepolia: {
url: `https://linea-sepolia.io/v3/${INFURA_API_KEY_LINEA}`,
accounts: [PRIVATE_KEY],
}, -
In the
hardhat.config.js
file, uncomment the following line:const PRIVATE_KEY = process.env.PRIVATE_KEY;
-
Deploy the smart contract to the Linea Sepolia testnet
npx hardhat run --network (lineaSepolia) scripts/deploy.js
Hardhat will return the deployed smart contract address in your terminal. View and verify your smart contract on the Linea Sepolia block explorer.
-
In your
.env
file, add your Infura Linea API key and add your wallet private key.INFURA_API_KEY_LINEA = "<YOUR API KEY HERE>"
WALLET_PRIVATE_KEY = "<YOUR PRIVATE KEY HERE>" -
In the
hardhat.config.js
file, add the following lines:const INFURA_API_KEY_LINEA = process.env.INFURA_API_KEY_LINEA;
linea: {
url: `https://linea-mainnet.io/v3/${INFURA_API_KEY_LINEA}`,
accounts: [PRIVATE_KEY],
}, -
In the
hardhat.config.js
file, uncomment the following line:const PRIVATE_KEY = process.env.PRIVATE_KEY;
-
Deploy the smart contract to the Linea Mainnet:
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 Mainnet block explorer.
Deploy your smart contract 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 example, we'll use Cookbook's Simple ERC-20 Token Smart Contract.
Prerequisites:
-
In the project directory, build the contracts:
forge build
If you encounter a "stack too deep" error, try running the following command instead
forge build --via
-
In the
scripts
directory, uncomment all the code in thecontract.s.sol
file. Replace"ARG1"
,"ARG2"
,2000
with yourToken Name
,Token Symbol
and desiredToken Quantity
where you see the code below:FixedToken _contract = new FixedToken("ARG1", "ARG2", 2000);
-
Update the
.env
file with your Linea RPC URL, followed by your MetaMask wallet private key and your Etherscan API key token values.noteThe example uses Goerli, but you can update it to use Mainnet or Sepolia instead.
-
Run the command to define your environment variables globally:
source .env
-
Deploy your contracts:
forge script script/contract.s.sol:ContractScript --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv
noteIf using Mainnet or Sepolia, then update the
--rpc-url
accordingly with the variable in the.env
file.
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 tests in the contract.t.sol
file are only examples, please generate your own.
Resources​
For more information on using Cookbook to find, learn about or build with smart contracts, see the following resources: