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

forc call help for callable functions #6950

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Dhanraj30
Copy link

Description

This PR enhances the forc call --help command to print out all callable functions of the contract from the provided ABI and provide examples of how to call each function. This makes it easier for users to know what functions are available on the callable contract. This update includes:

  • Parsing the ABI to retrieve callable functions.
  • Printing the list of functions available in the ABI.
  • Providing examples of how to call each function, including the required parameters.
  • Fixes issue Forc call help for callable functions #6935.

@Dhanraj30 Dhanraj30 marked this pull request as ready for review February 22, 2025 18:43
@Dhanraj30 Dhanraj30 requested a review from a team as a code owner February 22, 2025 18:43
@zees-dev
Copy link
Contributor

Thanks for this; however I was envisioning a different approach here.
For example; running forc call --help should print out the current help.
Running forc call --abi <..> <CONTRACT-ID> --help should parse the ABI; read the functions, and give examples on how to call them; below the current help output.
These should be something which can simply be copy-pasted by the user themselves for execution.
E.g.

> forc call --abi ./out/debug/counter-contract-abi.json 0xe18de7c7c8c61a1c706dccb3533caa00ba5c11b5230da4428582abf1b6831b4d --help
# current help output omitted..

Contract Functions:

add(u32,u32)
> forc call --abi ./out/debug/counter-contract-abi.json 0xe18de7c7c8c61a1c706dccb3533caa00ba5c11b5230da4428582abf1b6831b4d add 1 2

sub(u32,u32)
> forc call --abi ./out/debug/counter-contract-abi.json 0xe18de7c7c8c61a1c706dccb3533caa00ba5c11b5230da4428582abf1b6831b4d sub 1 2

Doesn't have to be perfect; i can imagine some complexity with complex structs/enums/generics - but something along these lines is what's expected.

@IGI-111
Copy link
Contributor

IGI-111 commented Feb 25, 2025

I like the idea, but --help is the wrong flag to use, it's much too standardized to just print usage for people to notice you can use it for more than that.

This should probably be some specific flag to list contract methods.

In fact maybe this is the sort of output you should get if you run forc call with an abi and a contract but no method. And have the tool suggest what you could call on this contract.

@zees-dev
Copy link
Contributor

I like the idea, but --help is the wrong flag to use, it's much too standardized to just print usage for people to notice you can use it for more than that.

This should probably be some specific flag to list contract methods.

In fact maybe this is the sort of output you should get if you run forc call with an abi and a contract but no method. And have the tool suggest what you could call on this contract.

I have seen the help flag used in other parts of the tooling which displays examples on how the tool can be called.

However no hard opinions here and I can see the other side of the argument (non-standardized output).

@zees-dev
Copy link
Contributor

@Dhanraj30 - Im encountering compile-time errors running code in this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants