Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@
"group": "Development with Foundry",
"pages": [
"learn/foundry/deploy-with-foundry",
"learn/foundry/deploy-smart-contracts-set-basenames",
"learn/foundry/setup-with-base",
"learn/foundry/testing-smart-contracts",
"learn/foundry/verify-contract-with-basescan",
Expand Down Expand Up @@ -1342,6 +1343,12 @@
"learn/hardhat/hardhat-deploy/hardhat-deploy-sbs"
]
},
{
"group": "Naming Smart Contracts",
"pages": [
"learn/hardhat/hardhat-naming/set-basenames-with-hardhat"
]
},
{
"group": "Verifying Smart Contracts",
"pages": [
Expand All @@ -1364,7 +1371,8 @@
"learn/hardhat/hardhat-tools-and-testing/analyzing-test-coverage",
"learn/hardhat/hardhat-tools-and-testing/optimizing-gas-usage",
"learn/hardhat/hardhat-tools-and-testing/reducing-contract-size",
"learn/hardhat/hardhat-tools-and-testing/deploy-with-hardhat"
"learn/hardhat/hardhat-tools-and-testing/deploy-with-hardhat",
"learn/hardhat/hardhat-tools-and-testing/set-basenames-with-hardhat"
]
}
]
Expand Down
1 change: 1 addition & 0 deletions docs/get-started/build-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ We now have a working onchain tally app! While the example is simple, it illustr

This is just the beginning. There are many ways we can improve upon this app. For example, we could:

- Set a Basename for your contract using [Foundry and the Enscribe library](/learn/foundry/deploy-smart-contracts-set-basenames).
- Make the `increment` transaction gasless by integrating with [Paymaster](/onchainkit/transaction/transaction#sponsor-with-paymaster-capabilities)
- Improve the wallet connection and sign up flow with the [WalletModal](/onchainkit/wallet/wallet-modal) component
- Add onchain [Identity](/onchainkit/identity/identity) so we know who added the most recent tally
1 change: 1 addition & 0 deletions docs/get-started/deploy-smart-contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ This will return the initial value of the Counter contract's `number` storage va

- Use [Onchainkit](https://onchainkit.com) to connect your frontend to your contracts! Onchainkit is a library of ready-to-use React components and Typescript utilities.
- Learn more about interacting with your contracts in the command line using Foundry from our [Foundry tutorial](/learn/foundry/deploy-with-foundry).
- Set a Basename for your contract using [Foundry and the Enscribe library](/learn/foundry/deploy-smart-contracts-set-basenames).
17 changes: 16 additions & 1 deletion docs/get-started/launch-token.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ Install OpenZeppelin contracts for secure, audited ERC-20 implementation:
forge install OpenZeppelin/openzeppelin-contracts
```

Install Enscribe contracts naming library for setting a Basename for your contracts:

```bash Terminal
# Install Enscribe contracts naming library
forge install enscribexyz/enscribe
```

### Smart Contract Development

Create your token contract using OpenZeppelin's ERC-20 implementation:
Expand All @@ -157,6 +164,7 @@ pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "enscribe/Ens.sol";

/**
* @title MyToken
Expand Down Expand Up @@ -229,6 +237,9 @@ contract DeployToken is Script {
initialSupply,
deployerAddress
);

// Set a Basename for the token contract assuming you have the mydomain.base.eth Basename registered on Base
Ens.setName(block.chainid, address(token), "myawesometoken.mydomain.base.eth");

// Stop broadcasting transactions
vm.stopBroadcast();
Expand Down Expand Up @@ -261,7 +272,7 @@ Update `foundry.toml` for Base network configuration:
src = "src"
out = "out"
libs = ["lib"]
remappings = ["@openzeppelin/=lib/openzeppelin-contracts/"]
remappings = ["@openzeppelin/=lib/openzeppelin-contracts/", "enscribe/=lib/enscribe/src/"]

[rpc_endpoints]
base_sepolia = "${BASE_SEPOLIA_RPC_URL}"
Expand Down Expand Up @@ -364,6 +375,10 @@ forge script script/DeployToken.s.sol:DeployToken \
--verify
```

<Tip>
You can see your contract's Basename by visiting [Enscribe Explorer](https://app.enscribe.xyz/explore/84532/myawesometoken.mydomain.base.eth).
</Tip>

<Tip>
The `--verify` flag automatically verifies your contract on BaseScan, making it easier for users to interact with your token.
</Tip>
Expand Down
190 changes: 190 additions & 0 deletions docs/learn/foundry/deploy-smart-contracts-set-basenames.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
title: 'Foundry: Naming a smart contract'
description: A guide to help you get started with deploying your smart contracts on Base and setting Basenames for them using Foundry.
---

Welcome to the Base deployment quickstart guide! This comprehensive walkthrough will help you set up your environment and deploy smart contracts on Base. Whether you're a seasoned developer or just starting out, this guide has got you covered.

## What You'll Achieve

By the end of this quickstart, you'll be able to:

- Set up your development environment to deploy on Base
- Deploy your smart contracts to Base and set Basenames for them

<Tip>
**Why Base?**

Base is a fast, low-cost, builder-friendly Ethereum L2 built to bring the next billion users onchain. By following this guide, you'll join a vibrant ecosystem of developers, creators, and innovators who are building a global onchain economy.
</Tip>


## Set Up Your Development Environment

1. Create a new project directory

```bash
mkdir my-base-project && cd my-base-project
```

2. Install Foundry, a powerful framework for smart contract development

```bash
curl -L https://foundry.paradigm.xyz | bash
foundryup
```

This installs Foundry and updates it to the latest version.

3. Initialize a new Solidity project

```bash
forge init
```

Your Foundry project is now ready. You'll find an example contract in the `src` directory, which you can replace with your own contracts. For the purposes of this guide, we'll use the Counter contract provided in `/src/Counter.sol`

<Tip>
Foundry provides a suite of tools for Ethereum application development, including Forge (for testing), Cast (for interacting with the chain), and Anvil (for setting up a local node). You can learn more about Foundry [here](https://book.getfoundry.sh/).
</Tip>


## Configure Foundry with Base

To deploy your smart contracts to Base, you need two key components:

1. A node connection to interact with the Base network
2. A funded private key to deploy the contract

Let's set up both of these:

### 1. Set up your node connection

1. Create a `.env` file in your project's root directory
2. Add the Base network RPC URL to your `.env` file

```bash
BASE_RPC_URL="https://mainnet.base.org"
BASE_SEPOLIA_RPC_URL="https://sepolia.base.org"
```

3. Load your environment variables

```bash
source .env
```

<Tip>
Base Sepolia is the test network for Base, which we will use for the rest of this guide. You can obtain free Base Sepolia ETH from one of the [faucets listed here](/base-chain/tools/network-faucets).
</Tip>


### 2. Secure your private key

1. Store your private key in Foundry's secure keystore

```bash
cast wallet import deployer --interactive
```

2. When prompted enter your private key and a password.

Your private key is stored in `~/.foundry/keystores` which is not tracked by git.

<Warning>
Never share or commit your private key. Always keep it secure and handle with care.
</Warning>


## Setup Your Contract for Naming using Foundry Script

We'll deploy the Counter contract using a Foundry script that will also set a Basename for the contract. First, ensure you have a Basename available to use. You can purchase a Basename from [base.org/names](https://base.org/names) or use a free Basename from the [faucets listed here](/base-chain/tools/network-faucets).

1. Install enscribesol

```bash
forge install enscribexyz/enscribe
```

2. Install openzeppelin

```bash
forge install OpenZeppelin/openzeppelin-contracts
```

3. Create `remapping.txt` and add the following remappings:

```
enscribe/=lib/enscribe/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
```

4. Make Counter implement Ownable

Update your `Counter.sol` contract to inherit from `Ownable`:

```solidity
import "@openzeppelin/contracts/access/Ownable.sol";

contract Counter is Ownable {
uint256 public number;

constructor(uint256 initialCount) Ownable(msg.sender) {
number = initialCount;
}

function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
}
}
```

5. Set a primary name for the contract address in `Counter.s.sol`. We'll use `enscribesol124.abhi.basetest.eth` for this example but you should use your own basename.

Update your deployment script to set a name for the contract:

```solidity
import {Script} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {Ens} from "enscribe/NameSetter.sol";

contract CounterScript is Script {
Counter public counter;

function setUp() public {}

function run() public {
vm.startBroadcast();

counter = new Counter(0);
Ens.setName(block.chainid, address(counter), "enscribesol124.abhi.basetest.eth");

vm.stopBroadcast();
}
}
```

## Deploy Your Contracts

Now that your environment is set up, let's deploy your contracts to Base Sepolia.

1. Use the following command to compile and deploy your contract

```bash
forge script ./src/Counter.s.sol:CounterScript --rpc-url $BASE_SEPOLIA_RPC_URL --account deployer
```

2. After successful deployment, the transaction hash will be printed to the console output

### Verify Basename Assignment

To ensure your Basename was assigned to the contract successfully:

1. Copy the contract address from the output
2. Navigate to https://app.enscribe.xyz/explore/84532/enscribesol124.abhi.basetest.eth to see the details of the contract we deployed and named.

** You've deployed your smart contracts to Base Sepolia and set Basenames for them!**
Loading