Skip to main content

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:

  1. Set up your wallet
  2. 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.

Cookbook Search

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.

Cookbook Analyze Code Snippet

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.

Cookbook Import Contract

Deploy a smart contract without coding​

Choose No-Code Deploy on select (usually simpler) smart contracts on Cookbook.

Cookbook No Code Deploy
  1. Connect your MetaMask Wallet to Cookbook.dev.

  2. Set your smart contract arguments in the Cookbook UI (if applicable).

  3. Select Linea or tLinea (Linea Testnet) under Pick Chain.

  4. 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​

  1. Go to Remix.Ethereum.org website.

  2. Add the Cookbook Plugin to Remix by clicking the Cookbook Logo under Featured Plugins on the Remix Homepage.

    Cookbook Remix Featured Plugin

    Alternatively, search Cookbook and select Activate in the Remix Plugin Manager.

    Cookbook Remix Add Plugin
  3. 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.

    Cookbook Remix Search
  4. 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​

  1. In the .env file, add your Infura Linea Goerli API key and add your wallet private key.

  2. 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],
    },
  3. 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.

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:

  1. 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
  2. In the scripts directory, 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);
  3. Update the .env file with your Linea RPC URL, followed by your MetaMask wallet private key and your Etherscan API key token values.

    note

    The example uses Goerli, but you can update it to use Mainnet or Sepolia instead.

  4. Run the command to define your environment variables globally:

    source .env
  5. Deploy your contracts:

    forge script script/contract.s.sol:ContractScript --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv
    note

    If 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.

note

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: