-
Notifications
You must be signed in to change notification settings - Fork 90
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
Equivalent of Solidity constructor #99
Comments
Hi @afosan , one pattern that could work for you today would be to use a multicall program to both deploy and activate in a single tx. Here's how: You can deploy a simple multicall program our team wrote in Rust for Stylus here. Then, you can prepare a deployment + activation in a single tx and interact with this multicall program: For the calldata needed to do a deployment, see here. For the calldata to do an activation, see here. To send a deployment tx, send the calldata for deployment to a nil address. To do an activation, send the activation calldata to the ARB_WASM_ADDRESS. You can put these together according to how the multicall program requires them and send them. This will guarantee atomic deploy + activation in one tx |
Thanks for the explanation @rauljordan! I also thought about employing multicall to achieve atomicity (not just for deployment and activation, also for "initialization" of the contract, e.g. where the owner is set). In fact, created an issue on multicall repo and it is now deployed on Stylus testnet here. I think both Multicall3 and Stylus implementation actually need modification though. Multicall3 always uses |
Is there an equivalent of Solidity constructor in Stylus? If not, is there any Stylus specific pattern you would suggest to achieve the same behavior?
I want to set a state variable to a value from
msg
context or passed as an argument to the constructor. Sharing a simple example Solidity contract to illustrate.edit: I have found an example using
init
function andinitialized
variable. It still seems possible that someone frontruns you to callinit
function (e.g. to become "owner" of the contract). Another example hardcodes the "owner" to prevent that.edit2: I have just found the part about constructors here. I feel it might be helpful to have a link to it under "Developer reference" section.
The text was updated successfully, but these errors were encountered: