Skip to content
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

feat: Add option to check any ERC20 token balance #25

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Pratham-19
Copy link

@Pratham-19 Pratham-19 commented Nov 24, 2024

Implementing

  • Check any token balance
  • Check balance for any address
  1. Check balance
  • Check any ERC20 token balance by default using the stored balance else can also provide address using
    rsk-cli balance --contract <address> --address (optional) -t

image

  • Added contract validation
    image

@Pratham-19 Pratham-19 marked this pull request as draft November 24, 2024 13:05
@chrisarevalodev
Copy link
Collaborator

chrisarevalodev commented Nov 26, 2024

Hey @Pratham-19!

I’m really impressed with your improvements to the CLI—they look fantastic. I have a few comments about your implementation that are critical to address before we can merge your PR.

I’ve already tested it, and it works well! However, there are some aspects of the implementation that don’t align with the existing CLI structure and the plans outlined for upcoming features in our backlog.

Specifically, you created a new program called token in the bin/index.ts file, where you can call both balance and transfer commands for custom tokens. While this is a great addition, there are already existing commands named balance and transfer. The goal is to update these commands so that users can execute them as follows:

  • Balance Command: Run rsk-cli balance or rsk-cli balance --testnet. Using inquirer and ora, the CLI should prompt the user to choose between rBTC, RIF, USD RIF, DoC, or a custom token. If the user selects custom, the CLI should then ask for the contract address using inquirer.

  • Transfer Command: Similarly, run rsk-cli transfer or rsk-cli transfer --testnet. Here too, the CLI should prompt the user to specify the token type (rBTC, RIF, etc.) or provide a contract address for custom tokens and also the amount to be transferred.

For reference, there is a very similar implementation using inquirer and ora in the contract command, which you may find helpful as a guide.

Thanks again for your hard work! You’re doing an amazing job. If you have any questions or need further clarification, feel free to reach out.

@Pratham-19
Copy link
Author

Thanks for your comment @chrisarevalodev

I got the requirements, I'll revamp my code and add inquirer and ora for the same

@Pratham-19 Pratham-19 marked this pull request as ready for review December 6, 2024 07:02
@Pratham-19
Copy link
Author

Hey @chrisarevalodev ,

These are the updates

  • Added support for rBTC, RIF, USD RIF, DoC, and custom tokens on both mainnet and testnet (need help regarding testnet contract addressfor these tokens)

image

image

  • Added support for checking balance of any specified address

image

  • Added contract address validation

image

@Pratham-19 Pratham-19 changed the title feat: Add token command to check any ERC20 balance, transfer ERC20 feat: Add option to check any ERC20 balance Dec 6, 2024
@Pratham-19 Pratham-19 changed the title feat: Add option to check any ERC20 balance feat: Add option to check any ERC20 token balance Dec 6, 2024
@chrisarevalodev
Copy link
Collaborator

chrisarevalodev commented Dec 6, 2024

Hey @Pratham-19, I like how the updates are looking! 👀. However, I noticed some bugs that I'm going to describe below.

  1. I ran rsk-cli balance -t and got the error 🚫 No saved wallet found. That one is completely fine. The problem is that after I create a wallet and run rsk-cli balance -t the rootstock logo is logged and the command just ends. I was diving into the bug and the problem is in the getAddress function from utils.

    The problem is in this line:

    const { address: savedAddress } = JSON.parse(
          fs.readFileSync(walletFilePath, "utf8")
    );

    Because you're trying to get the address property from the file where the wallets are saved but there's no address property in there. Please make sure to check the structure of the JSON and make the proper corrections. I'll leave here an example of the JSON file:

    image
  2. I tried querying the balance of a custom token passing an address of an ERC721 (incorrect) and an error was indeed triggered but the spinner never ends (see image below). You can check how the errors are being handled in other commands like the contract command. Tip: You can add spinner.fail(<Error message>) on error so the spinner ends after an error.

    image

Please check on these comments and make the proper updates so we can approve it and merge it! You've done a great work.

@Pratham-19
Copy link
Author

Hey @chrisarevalodev ,

I have added a function to check whether the contract is erc20, so it will only work for all the ERC20 contract

image

Copy link
Collaborator

@chrisarevalodev chrisarevalodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and working. LGTM @ezequiel-rodriguez

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokens must be: RIF, USDRIF (instead of rUSDT) and DoC (instead of rDoc). Here you can find all these token's addresses in mainnet and testnet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file and use erc20abi constant that can be imported from viem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecesary blank spaces

getTokenInfo,
isERC20Contract,
resolveTokenAddress,
} from "../utils/tokenHelper.js";
import ora from "ora";
import { console } from "inspector";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the line with import:

import { console } from "inspector";

as it is not necessary. Just use default console.log function

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