-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
plugin: forc-call #6791
Draft
zees-dev
wants to merge
16
commits into
master
Choose a base branch
from
feat/forc-call
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
plugin: forc-call #6791
Conversation
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
zees-dev
added
ABI
Everything to do the ABI, especially the JSON representation
forc-client
Everything related to the `forc-client` crate.
labels
Dec 17, 2024
…upport for dry-run
…e execution modes; added gas -> txpolicies conversion function
zees-dev
force-pushed
the
feat/forc-call
branch
from
January 6, 2025 23:21
ead0e1f
to
945e38e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ABI
Everything to do the ABI, especially the JSON representation
forc-client
Everything related to the `forc-client` crate.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The following PR introduces a new forc plugin;
forc-call
.This plugin allows users to call functions on deployed contracts using the
forc call
command.This is ideal for quickly querying the state of a deployed contract.
In this first implementation; the contract ABI is required (as a path to a local JSON file or a URL to a remote JSON file).
This is inspired by the
cast call
tool; which is a popular tool for interacting with deployed contracts on Ethereum.The implementation is based on the following Github issue: #6725
In the current implementation, you can query a contract state using the
forc call
command by providing the target contract ID, it's respective ABI file, and the function name (selector) and arguments.Forc Call CLI
Example usage
0xe18de7c7c8c61a1c706dccb3533caa00ba5c11b5230da4428582abf1b6831b4d
is the contract ID./out/debug/counter-contract-abi.json
is the path to the ABI fileadd
is the function name (selector)1 2
are the arguments to the function^ the sway code for the add function could be:
Implementation details
add
is matched with the extracted functions from the ABIToken
enum, which is then ABI encoded as part of theContractCall
structContractCall
struct is then used to make a request to the node to call the function^ In the implementation, we don't use the
abigen!
macro since this is a compile time parser of the ABI file; instead we make use of the lower level encoding and decoding primitives and functions from the Rust SDK.Live example on testnet
Example 1
The example contract above with
add
function has been deployed on testnet - with ABI file available here.The add function can be called via the CLI:
Example 2 - get
owner
of Mira DEX contractNote: Testnet contract address here
Encoding of primitive types
When passing in function arguments, the following types are encoded as follows:
true
orfalse
42
0x0000000000000000000000000000000000000000000000000000000000000042
or0000000000000000000000000000000000000000000000000000000000000042
0x
prefix is optional0x42
or42
0x
prefix is optional"abc"
(42, true)
[42, 128]
[42, true]
{42, 128}
{42, 128}
; this could represent the followingstruct Polygon { x: u64, y: u64 }
(Active: true)
or(1: true)
enum MyEnum { Inactive, Active(bool) }
Encoding cheat-sheet
A few of the common types are encoded as follows:
bool
: 0x00 (false) or 0x01 (true);u8
is the byte itself.bool(true) = 0x01
,u8(42) = 0x2A
u16(42) = 0x002A
u32(42) = 0x0000002A
u64(42) = 0x000000000000002A
u128(42) = 0x0000000000000000000000000000002A
u256(42) = 32-bytes ending with ...0000002A
,b256(...) = exactly the 32-byte array
(u8(1), bool(true)) = 0x01 0x01
;[u16;2]: [42,100] = 0x002A0064
;struct {u8,u8}: 0x0102
u64
variant index + encoded variant data with no extra paddingMySumType::X(42): 0x0000000000000000 000000000000002A
u64
length prefix + raw data, no padding"abc" = length=3: 0x0000000000000003 0x61 0x62 0x63
^ This is based on the docs here: https://docs.fuel.network/docs/specs/abi/argument-encoding
Future improvements
Checklist
Breaking*
orNew Feature
labels where relevant.