rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

Get bytes from Contract builder

Open justindthomas opened this issue 4 years ago • 4 comments

I'm trying to piece together how I can deploy a contract from bytecode and ABI using the private key to sign the transaction (i.e., without requiring that the account and key be stored on the Ethereum node). I think I can use send_raw_transaction to do it using the rlp crate to encode the data.

But I can't find a way to build the Contract with arguments and get its bytes without actually executing the deploy. Is there a way to do that that I'm overlooking? I do see several issues kind of talking around this issue of deploying contracts without unlocking the account at the node, but I'm wondering if there's an immediate workaround or if I just need to give up for now (or fumble my way through submitting a PR - which would probably be pretty ugly given my current Rust proficiency). :)

justindthomas avatar Jan 05 '21 20:01 justindthomas

Indeed, deployment using a signed account is not really supported, it shouldn't be that hard to add though. Take a look at: https://github.com/tomusdrw/rust-web3/blob/a0c18680646828df5c70500c7de28bedfa609f9f/src/contract/mod.rs#L288

and it needs to be plugged somewhat like this into the deploy pipeline: https://github.com/tomusdrw/rust-web3/blob/a0c18680646828df5c70500c7de28bedfa609f9f/src/contract/deploy.rs#L84 (make sure to create a separate, feature-gated method for this)

tomusdrw avatar Jan 05 '21 22:01 tomusdrw

That's great - thank you for the detailed advice. I'll see if I can put something together.

justindthomas avatar Jan 05 '21 22:01 justindthomas

Am I reading this correctly that do_execute is already set up to handle parameters when deploying the contract?

https://github.com/tomusdrw/rust-web3/blob/a0c18680646828df5c70500c7de28bedfa609f9f/src/contract/deploy.rs#L136

justindthomas avatar Jan 05 '21 23:01 justindthomas

Yes, I think so.

tomusdrw avatar Jan 05 '21 23:01 tomusdrw