-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ivegabr/docs/DV-547-foundry-docs-automation
Docs/dv 547 foundry docs automation
- Loading branch information
Showing
2 changed files
with
103 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Update Devportal Documentation | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'README.md' | ||
|
||
jobs: | ||
update-docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
# Step 1: Clone the Devportal Repository | ||
- name: Clone Devportal Repository | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.DEVPORTAL_DOCS_UPDATE_TOKEN }} | ||
run: | | ||
git clone https://github.com/rsksmart/devportal.git | ||
cd devportal | ||
git checkout -b update-from-foundry-starter || git checkout update-from-foundry-starter | ||
cd .. | ||
# Step 2: Transform Each File and Copy to Devportal Repository | ||
- name: Transform Files for Devportal | ||
run: | | ||
mkdir -p transformed | ||
# Process README.md | ||
echo "---" > transformed/README.md | ||
echo "sidebar_label: Rootstock Foundry Starter kit" >> transformed/README.md | ||
echo "sidebar_position: 500" >> transformed/README.md | ||
echo "title: Rootstock Foundry Starter kit" >> transformed/README.md | ||
echo "description: 'Whether you are a seasoned developer or just starting your journey into smart contract development, the foundry starter kit provides a solid foundation for building decentralized applications (dApps) on the Rootstock network.'" >> transformed/README.md | ||
echo "tags: [rsk, rootstock, tutorials, developers, foundry, quick starts, dApps, smart contracts]" >> transformed/README.md | ||
echo "---" >> transformed/README.md | ||
echo "" >> transformed/README.md | ||
echo ":::info[Note]" >> transformed/README.md | ||
echo "You can add your suggestion on the [Foundry Starter Kit Repository](https://github.com/rsksmart/rootstock-foundry-starterkit.git)" >> transformed/README.md | ||
echo ":::" >> transformed/README.md | ||
echo "" >> transformed/README.md | ||
cat README.md >> transformed/README.md | ||
cp transformed/README.md devportal/docs/02-developers/04-quickstart/foundry.md | ||
# Step 3: Commit and Push Changes to Devportal Repository | ||
- name: Commit and Push Changes | ||
run: | | ||
cd devportal | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
git add docs/02-developers/04-quickstart/foundry.md | ||
git commit -m "Automated update from repository" | ||
git push -f origin update-from-foundry-starter | ||
# Step 4: Create a Pull Request in the Devportal Repository | ||
- name: Create Pull Request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.DEVPORTAL_DOCS_UPDATE_TOKEN }} | ||
run: | | ||
cd devportal | ||
curl -L -X POST -H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ secrets.DEVPORTAL_DOCS_UPDATE_TOKEN }}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/rsksmart/devportal/pulls \ | ||
-d '{"title":"Automated update of documentation","body":"This PR updates the Devportal documentation with the latest changes from the original repository.","head":"update-from-foundry-starter","base":"main"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,10 @@ | ||
<img src="img/rootstock.png" alt="RSK Logo" style="width:100%; height: auto;" /> | ||
|
||
# Rootstock Foundry Starter Kit | ||
|
||
## Rootstock Foundry Starter Kit Configuration | ||
This starter kit provides a ready-to-use setup for developing, testing, and deploying smart contracts on the [Rootstock](https://rootstock.io/) network using [Foundry](https://book.getfoundry.sh/). It includes essential tools and configurations to streamline your workflow, ensuring best practices and efficient development. | ||
|
||
## Project Structure | ||
Whether you’re a seasoned developer or just starting your journey into smart contract development, the foundry starter kit provides a solid foundation for building decentralized applications (dApps) on the Rootstock network. | ||
|
||
``` | ||
├── foundry.toml | ||
├── remappings.txt | ||
├── script | ||
│ └── Deploy.s.sol | ||
├── src | ||
│ └── Erc20Token.sol | ||
├── test | ||
│ └── Erc20Token.t.sol | ||
└── .env.example | ||
├── img/rootstock.png | ||
├── broadcast/ | ||
├── lib/ | ||
├── out/ | ||
├── README.md | ||
``` | ||
### Main Folders | ||
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. | ||
|
||
- **src:** This folder contains the main smart contracts of the project. Here you will define the core logic of your application. | ||
- **script:** This folder contains the deployment scripts for the smart contracts. These scripts are used to deploy your contracts to the blockchain. | ||
- **test:** This folder contains the test files for your smart contracts. It is used to write and run tests to ensure that your contracts behave as expected. | ||
|
||
## Supported Networks | ||
|
||
- Foundry Test Network | ||
- Rootstock Mainnet | ||
- Rootstock Testnet | ||
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 | ||
|
||
|
@@ -43,20 +14,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/). | ||
|
@@ -78,36 +51,45 @@ git clone https://github.com/rsksmart/rootstock-foundry-starterkit.git | |
|
||
### Install Dependencies | ||
|
||
Navigate to the cloned repository folder: | ||
|
||
```bash | ||
cd rootstock-foundry-starterkit | ||
``` | ||
|
||
Install all required dependencies using forge: | ||
|
||
```bash | ||
forge install OpenZeppelin/openzeppelin-contracts | ||
forge install openzeppelin-contracts-05=OpenZeppelin/openzeppelin-contracts@v2.5.0 openzeppelin-contracts-06=OpenZeppelin/[email protected] openzeppelin-contracts-08=OpenZeppelin/[email protected] --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 | ||
|
||
After obtaining the RPC URLs, create a file named `.env` in your project's root directory (important: this file should not be committed to version control). Add the necessary environment variables to the `.env` file: | ||
After obtaining the RPC URLs, create a file named `.env` in your project's root directory `/.env` at the same level of `.env.example` file (important: this file should not be committed to version control). Add the next environment variable to the `.env` file: | ||
``` | ||
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 `0x...` | ||
::: | ||
|
||
|
||
## 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: | ||
|
||
|
@@ -130,23 +112,24 @@ 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 | ||
forge script script/Deploy.s.sol --rpc-url https://public-node.testnet.rsk.co --broadcast --legacy --evm-version london | ||
``` | ||
:::info[Info] | ||
|
||
- [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) is not supported or not activated on the Rootstock RPC url | ||
- [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) is not supported or not activated on the Rootstock RPC url. | ||
- To avoid Foundry's compatibility issues, we are using the `--evm-version london` flag. | ||
- 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 | ||
|
@@ -167,7 +150,7 @@ Total Paid: 0. ETH (106719 gas * avg 0 gwei) | |
``` | ||
## 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. | ||
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: | ||
|
@@ -182,4 +165,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. |