Skip to content

Docs: Create new tutorial using foundry + rsk-foundry-starter-kit #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

BrunoCampana
Copy link

@BrunoCampana BrunoCampana commented May 2, 2025

Title

  • Create a new tutorial to demonstrate how to use the rsk-foundry-starter-kit with Foundry

Description

A step-by-step tutorial on how to develop a smart contract in Solidity using the Foundry SDK and the rootstock-foundry-starter-kit, deploy it on the Rootstock testnet, and test its flow.

The tutorial uses the use case of BTC-denominated bonds as an illustration.

This PR makes only the following changes:

  • Adds a single new file containing the tutorial.
  • Updates the index to include it in the sidebar menu.

Screenshots/GIFs

New page:

bond-contract-tutorial

Tutorial added to left side bar:

bond-contract-tutorial-2

Testing

  • N/A

Checklist

  • I have read and understood the contributing guidelines.
  • I have followed the style guide and formatting guidelines.
  • I have added appropriate comments to explain the changes.
  • I have tested my changes thoroughly.

Refs

  • N/A

Copy link

vercel bot commented May 2, 2025

@BrunoCampana is attempting to deploy a commit to the IOV Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented May 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
devportal-rootstock ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2025 1:31pm

@owans
Copy link
Collaborator

owans commented May 6, 2025

Hi @BrunoCampana,

Thank you for the submission. Could you please review this error:

This was gotten after running forge build.

`
Compiler run successful with warnings:
Warning (2072): Unused local variable.
--> src/Bond.sol:111:5:
|
111 | uint256 interestWei = ((principalWei * ((100 + couponRate) ** (couponFrequency * tenor))) / (100 ** (couponFrequency * tenor))) - principalWei;
| ^^^^^^^^^^^^^^^^^^^

`

@BrunoCampana
Copy link
Author

BrunoCampana commented May 7, 2025

Hi @owans

Let's go over the output you got from following the tutorial. This behavior is 100% expected. I got it too. Let's review it together. Let's begin:

1 You ran the command forge build.

This command compiles the smart contract's source code. Then you received the following message:

Compiler run successful with warnings:
Warning (2072): Unused local variable.
--> src/Bond.sol:111:5:
|
111 | uint256 interestWei = ((principalWei * ((100 + couponRate) ** (couponFrequency * tenor))) / (100 ** (couponFrequency * tenor))) - principalWei;
| ^^^^^^^^^^^^^^^^^^^

2 The first line is the most important one:

Compiler run successful with warnings
It informs us that the compiler ran successfully. That means the Solidity source code was correctly compiled into bytecode. There were no compilation failures, and the smart contract is ready to be deployed on a blockchain.

3 However, as you noticed, there is a message to analyze.

In this case, the message is not an "error" but a "warning": Unused local variable , and it points to the line where the warning was raised.

Basically, the variable interestWei was declared and assigned a value using the formula, but it isn’t used anywhere. It’s simply left unused.

4 Is that a problem?

It depends. This could be a sign of a bug. But that’s not the case here. Also, when executing a contract on the EVM, each additional opcode consumes gas. So although this line doesn’t affect the contract’s behavior, it is not a good practice and shouldn't be present this way in production environment.

5 So why was this variable left in the code unused?

Well, this variable uses the standard compound interest formula to calculate what the actual redemption of the contract would be. Note that I didn't create this formula—it’s the standard one used for this calculation in financial math.

This is the correct line for the contract. However, this formula only works correctly with future timestamps, after X years.

To test this specific formula, I would need to use unit tests and run full integration tests on a local blockchain using a mock blockchain.

All of that would take a lot of time and would make the tutorial—which is already complex—even more complex.

Moreover, my goal was to deploy the contract on Rootstock public testnet and for the flow test of the contract behavior to be done on it.

6 So what solution was adopted?

The solution was to test the entire behavior except for this formula.
I commented out the two lines below this one that used the variable and added two lines to carry out the test.

I made this observation in the step where I wrote that function. I could have commented this line too, but since it didn’t change anything, I chose to change the correct code as little as possible.

Furthermore, I preferred to comment out only the strictly necessary two lines and add only the two required ones.
This makes it easier to locate where to change the code later.

Note that it was done this way because this smart contract example is a fully functional PoC meant to implement the use case of Treasury bonds in this context. Hence the need to keep the formula and this line.

In a nutshell: this warning is just happening because it is a "test version" of the contract.

7 Ok, but what should we do??

Note that I also received this same warning message every time I compiled the "changed contract version".

I chose to leave it because I saw value in keeping it: I considered it easy to understand and quite useful as a reminder that lines were added for testing purposes.

However, I understand that it might not be ideal to keep this warning message. It was left intentionally for didactic purposes, but it could potentially confuse developers who are less experienced with Solidity and the EVM.

Do you think it's necessary to clarify this point in the tutorial?
If so, we can make a small change.

Given all of this, we have the following options to proceed:

Option 1: comment out this line as well. The warning disappears. But it becomes harder to adjust the code later.

Option 2: keep the code as-is but add an explanation about the warning.

Option 3: keep the tutorial as-is without changing anything. The developer would need to read and interpret the message.

Option 4: modify the forge build command to silence warnings: forge build --no-warnings.

Please let me know which course of action you consider best to improve the tutorial, and I’ll add a new commit with the change if necessary.

@BrunoCampana BrunoCampana closed this by deleting the head repository Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants