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(cast) add deploydata method #8973

Closed
pawurb opened this issue Sep 27, 2024 · 1 comment · Fixed by #9029
Closed

feat(cast) add deploydata method #8973

pawurb opened this issue Sep 27, 2024 · 1 comment · Fixed by #9029
Assignees
Labels
C-cast Command: cast T-feature Type: feature

Comments

@pawurb
Copy link
Contributor

pawurb commented Sep 27, 2024

Component

Cast

Describe the feature you would like

Hi. One way to deploy a contract with Alloy is to use an artifact. It requires an artifact file by compiling the contracts locally. Other methods require manually embedding the API and bytecode.

Maybe I've overlooked something but I did not find a simple way to get bytecode without local compilation or forge inspect that also require local setup. Etherscan shows bytecode (as Contract Creation Code) in the UI but I could not find an API to get it directly. eth_getCode returns the deployed bytecode.

I want to propose adding cast deploydata <address> method. It would produce a file which contains the contracts ABI and bytecode fetched from the etherscan API in this format. This data is all that's necessary to deploy a contract with Alloy sol! macro. I've created a POC here: https://github.com/pawurb/alloy_deploydata .

ABI fetching is already implemented. Tx where a contract was created can be fetched from etherscan like this:

https://api.etherscan.io/api?module=contract&action=getcontractcreation&contractaddresses=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&apikey=API_KEY

Returning:

{"status":"1","message":"OK","result":[{"contractAddress":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","contractCreator":"0x4f26ffbe5f04ed43630fdc30a87638d53d0b0876","txHash":"0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3"}]}

Later we can call:

https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3&apikey=API_KEY

If in the result to is null it means that input is the bytecode we need.

If result is not null means that contract was deployed with some factory pattern or create2. In the case it's still possible to get the bytecode with debug_traceTransaction/callTracer. But it would require an rpc and could work as a fallback.

This feature would allow users to easily deploy and test contracts without compiling them locally.

We could also add cast bytecode which would return contract's bytecode.

Let me know if you'd accept this feature and I can look into creating a PR.

Additional context

No response

@pawurb pawurb added T-feature Type: feature T-needs-triage Type: this issue needs to be labelled labels Sep 27, 2024
@pawurb pawurb changed the title add deploydata method feat(cast) add deploydata method Sep 27, 2024
@pawurb pawurb changed the title feat(cast) add deploydata method feat(cast) add deploydata method Sep 27, 2024
@estherbreath
Copy link

Hi @pawurb
I am a smart contract and full stack developer.
can I please work on this issue?

@zerosnacks zerosnacks added C-cast Command: cast and removed T-needs-triage Type: this issue needs to be labelled labels Oct 4, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 4, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 4, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 4, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 4, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 4, 2024
@zerosnacks zerosnacks linked a pull request Oct 4, 2024 that will close this issue
pawurb added a commit to pawurb/foundry that referenced this issue Oct 10, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 10, 2024
pawurb added a commit to pawurb/foundry that referenced this issue Oct 16, 2024
grandizzy pushed a commit that referenced this issue Oct 29, 2024
* feat(cast) add creation-code method [#8973]

* Fix typo

* Fix CI

* Code review fixes

* Add creation-code flags and creation-args

* Update comments

* eyre style fixes

* typo

* use r#".."# for snapbox

* Apply suggestions from code review

* fix test regression

* tag arguments as mutually exclusive

* use unreachable!

* Rename and add abi_path param

* Decode constructor args

* Update crates/cast/bin/cmd/constructor_args.rs

* fix test

* Update crates/cast/bin/args.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Update crates/cast/bin/cmd/creation_code.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Update crates/cast/bin/cmd/creation_code.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Fix formatting

* Code review fixes

---------

Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
rplusq pushed a commit to rplusq/foundry that referenced this issue Nov 29, 2024
* feat(cast) add creation-code method [foundry-rs#8973]

* Fix typo

* Fix CI

* Code review fixes

* Add creation-code flags and creation-args

* Update comments

* eyre style fixes

* typo

* use r#".."# for snapbox

* Apply suggestions from code review

* fix test regression

* tag arguments as mutually exclusive

* use unreachable!

* Rename and add abi_path param

* Decode constructor args

* Update crates/cast/bin/cmd/constructor_args.rs

* fix test

* Update crates/cast/bin/args.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Update crates/cast/bin/cmd/creation_code.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Update crates/cast/bin/cmd/creation_code.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

* Fix formatting

* Code review fixes

---------

Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast T-feature Type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants