Skip to content

Commit

Permalink
merging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SebasGuaquetaRSK committed Oct 15, 2024
2 parents 1a58d03 + 381365c commit d7feee0
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions docs/02-developers/04-quickstart/foundry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Whether you’re a seasoned developer or just starting your journey into smart c

Rootstock is fully EVM (Ethereum Virtual Machine) compatible. It brings the power of smart contracts to Bitcoin, allowing developers to leverage Bitcoin’s security while benefiting from Ethereum’s ecosystem.

In this tutorial, you'll learn how to set up your Foundry development environment, connect to a Rootstock network, write and test smart contracts, deploy them to the Rootstock blockchain, and interact with them. We'll guide you through every step, from installation to minting your first token.

## Prerequisites

Before starting the dApp, make sure to have the following prerequisites:
Expand All @@ -18,20 +20,22 @@ Before starting the dApp, make sure to have the following prerequisites:
- If you’re new to smart contracts, consider learning the basics. Understanding how smart contracts work will enhance your experience with Rootstock development.

2. **Foundry installation using [Foundryup](https://book.getfoundry.sh/getting-started/installation#using-foundryup):**
- This installing information is taken from the official [Foundry documentation](https://book.getfoundry.sh/getting-started/installation#using-foundryup), in case you need to go in detail.
- Foundryup is the official installer for the Foundry toolchain. You can learn more about it [here](https://github.com/foundry-rs/foundry/blob/master/foundryup/README.md).
- To install, visit the official [Foundry documentation](https://book.getfoundry.sh/getting-started/installation#using-foundryup), for more information.
- Foundryup is the official installer for the Foundry toolchain. You can learn more about it in the [Foundryup README](https://github.com/foundry-rs/foundry/blob/master/foundryup/README.md).
- If you encounter any issues during installation, refer to the Foundryup [FAQ](https://book.getfoundry.sh/faq.html) for assistance.
- Precompiled binaries can be downloaded from the Foundry [GitHub releases page](https://github.com/foundry-rs/foundry/releases). For easier management, we recommend using Foundryup.

To install Foundry in your system, run the following command:
```bash
curl -L https://foundry.paradigm.xyz | bash
```
This will install Foundryup. Simply follow the on-screen instructions, and the ```foundryup``` command will become available in your CLI.
This will install Foundryup. Follow the on-screen instructions, and the `foundryup` command will be available via the CLI.

Running ```foundryup``` will automatically install the latest (nightly) versions of the ```precompiled binaries```: ```forge```, ```cast```, ```anvil```, and ```chisel```. For additional options, such as installing a specific version or commit, run ```foundryup --help```.
Running `foundryup` automatically installs the latest (nightly) versions of the precompiled binaries: `forge`, `cast`, `anvil`, and `chisel`. For additional options, such as installing a specific version or commit, run `foundryup --help`.

**_NOTE: If you’re using Windows, you’ll need to install and use [Git BASH](https://gitforwindows.org/) or [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) as your terminal, since Foundryup currently doesn’t support Powershell or Command Prompt (Cmd)._**
:::info[Using Windows]
If you’re using Windows, you’ll need to install and use [Git BASH](https://gitforwindows.org/) or [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) as your terminal, since Foundryup currently doesn’t support Powershell or Command Prompt (Cmd).
:::

3. **Basic Knowledge of Foundry:**
- Familiarity with Foundry's core concepts and functionalities is recommended. If you're new to Foundry, refer to the [Rootstock Foundry Guide](/developers/smart-contracts/foundry/).
Expand Down Expand Up @@ -65,18 +69,18 @@ Install all required dependencies using forge:
forge install openzeppelin-contracts-05=OpenZeppelin/openzeppelin-contracts@v2.5.0 openzeppelin-contracts-06=OpenZeppelin/openzeppelin-contracts@v3.4.0 openzeppelin-contracts-08=OpenZeppelin/openzeppelin-contracts@v4.8.3 --no-commit
```

### Obtain Rootstock Testnet and Mainnet RPC URLs
### Add Rootstock Testnet and Mainnet RPC URLs

This section will walk you through adding Rootstock Testnet and Mainnet RPC URLs to your development environment. These URLs are essential for connecting your application to the Rootstock network and interacting with smart contracts.

There are two ways to obtain RPC URLs:

#### Using Public RPC URLs

- Visit the [MetaMask Integration on the Rootstock Dev Portal](/dev-tools/wallets/metamask/). This guide provides instructions on setting up MetaMask for Rootstock. While following these steps, pay close attention to the sections on adding custom networks. You'll find the RPC URLs for Rootstock Testnet and Mainnet listed.
- Visit the [MetaMask Integration on the Rootstock DevPortal](/dev-tools/wallets/metamask/). This guide provides instructions on setting up MetaMask for Rootstock. While following these steps, pay close attention to the sections on adding custom networks. You'll find the RPC URLs for Rootstock Testnet and Mainnet listed.

#### Using RPC API
- Create an account at the [Rootstock RPC API](https://rpc.rootstock.io/). Once logged in, navigate to your dashboard and copy the API Key.
- Create an account on the [Rootstock RPC API](https://rpc.rootstock.io/). Once logged in, navigate to your dashboard and copy the API Key.


### Adding environment variables to your project
Expand All @@ -85,10 +89,13 @@ After obtaining the RPC URLs, create a file named `.env` in your project's root
```
PRIVATE_KEY: Your private key (e.g., from your Metamask account details).
```
**_NOTE: Make sure the private key you paste, starts with 0x, if does not contain it, please put 0x before your private key. (0x123...)_**
:::tip[Tip]
Ensure the private key copied starts with `0x123...`
:::


## Running tests to an ERC20 Token Contract
This section runs tests on an ERC20 token contract (fungible token), this is done according to the script located at ```test/Erc20Token.t.sol```. It does test deployment, minting, and transfer of tokens.
## Running tests on an ERC20 Token Contract
This section runs tests on an ERC20 token contract (fungible token), this is done according to the script located at `test/Erc20Token.t.sol`. It does test deployment, minting, and transfer of tokens.

For this, run the next forge command:

Expand All @@ -111,9 +118,9 @@ Ran 1 test suite in 143.90ms (8.73ms CPU time): 2 tests passed, 0 failed, 0 skip
**_NOTE: If you need additional tests, or want to go deep on this step, visit the [Foundry Tests Documentation](https://book.getfoundry.sh/forge/tests)._**

## Deploying an ERC20 Token Contract
This section deploys an ERC20 token contract (fungible token) on the Rootstock network. This contract is located at ```src/Erc20Token.sol``` file, it uses the script located at ```script/Deploy.s.sol``` for this operation.
This section deploys an ERC20 token contract (fungible token) on the Rootstock network. This contract is located at `src/Erc20Token.sol` file, it uses the script located at `script/Deploy.s.sol` for this operation.

Run the following command, replacing `https://public-node.testnet.rsk.co` with either `rskTestnet` or `rskMainnet` rpc url if you have, depending on your desired deployment environment:
Run the following command, replacing `https://public-node.testnet.rsk.co` with either `rskTestnet` or `rskMainnet` rpc url if you have the testnet and mainnet environments configured for your desired deployment environment, for this guide, we will use the public node url:

```bash
forge script script/Deploy.s.sol --rpc-url https://public-node.testnet.rsk.co --broadcast --legacy
Expand All @@ -122,12 +129,12 @@ forge script script/Deploy.s.sol --rpc-url https://public-node.testnet.rsk.co --

- [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) is not supported or not activated on the Rootstock RPC url
- The `--legacy` flag is passed to use legacy transactions instead of `EIP-1559`.
- You can remove the `--broadcast` flag if you wan to simulate the transaction without broadcasting it.
- You can remove the `--broadcast` flag if you want to simulate the transaction without broadcasting it.
:::

> If you get an error like `Transaction dropped from the mempool: <tx-id>` or the ```transaction not completed```, check the tx-id in the explorer. The tx may have went successful but the error is still in the logs. Here are the [mainnet](https://explorer.rootstock.io/) and [testnet](https://explorer.testnet.rootstock.io/) explorers.
> If you encounter an error such as `Transaction dropped from the mempool: <tx-id>` or `transaction not completed`, check the `tx-id` in the explorer. The transaction may have been successful but the error is still within the logs. See the [mainnet](https://explorer.rootstock.io/) and [testnet](https://explorer.testnet.rootstock.io/) explorers for more info.
> Also you can see the transaction registry locally, by checking the folder ```broadcast/Deploy.s.sol/``` and opening the file called ```run-latest.json```, if you check the fields, there is one called ```contractAddress``` which contains the new address deployed for our ERC20 smart contract.
> Also you can see the transaction registry locally, by checking the folder `broadcast/Deploy.s.sol/` and opening the file called `run-latest.json`. See the field called `contractAddress` which contains the new address deployed for the ERC20 smart contract.
The result should look like this:
```bash
Expand All @@ -147,8 +154,8 @@ ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
Total Paid: 0. ETH (106719 gas * avg 0 gwei)
```
## Interacting with the Contract
If the contract is already deployed, then you can interact with it using ```cast``` this command allows you to interact with the contract, in this case, read the balance of an account.
## Interacting with the Contract - Minting a Token
If the contract is already deployed, then you can interact with it using `cast` this command allows you to interact with the contract, in this case, read the balance of an account.
### Reading the Balance of an Account
In your terminal, run the following command, replacing the placeholders with actual values:
Expand All @@ -163,4 +170,4 @@ The result should look like this:
## Final Comments
Explore and be curious about the folders and files of this starter kit. You'll learn how to import `.env` variables for deploying smart contracts, test smart contracts with solidity. Feel free to customize this starter kit to suit your project’s needs. Happy coding!
You can explore the folders and files within the starter kit and customize the kit to suit your project’s needs. You can also learn how to import `.env` variables for deploying smart contracts, test smart contracts with solidity, etc.

0 comments on commit d7feee0

Please sign in to comment.