-
Notifications
You must be signed in to change notification settings - Fork 313
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: add new static method to contract Client to deploy and construct contracts #1086
Conversation
A Question on API DesignWhich do you prefer? Also feel free to suggest other ideas! Note: all examples below are using a simple Option 1 (Current Behavior)Right now, we have it working like this: // this returns an AssembledTransaction which, when sent, returns a `Client`
const deployTx = await contract.Client.deploy(
{ counter: INIT_VALUE },
{
networkPassphrase,
rpcUrl,
wasmHash,
publicKey,
signTransaction,
},
);
const { result: client } = await deployTx.signAndSend();
const { result } = await client.counter();
expect(result, INIT_VALUE); This makes maximum use of existing Option 2That const deployTx = await contract.Client.deploy(
{ counter: INIT_VALUE },
{
networkPassphrase,
rpcUrl,
wasmHash,
publicKey,
signTransaction,
},
);
-const { result: client } = await deployTx.signAndSend();
+const client = await deployTx.signAndSend();
const { result } = await client.counter();
expect(result, INIT_VALUE);
Option 3But then, is it worth requiring people to call -const deployTx = await contract.Client.deploy(
+const client = await contract.Client.deploy(
{ counter: INIT_VALUE },
{
networkPassphrase,
rpcUrl,
wasmHash,
publicKey,
signTransaction,
},
);
-const { result: client } = await deployTx.signAndSend();
const { result } = await client.counter();
expect(result, INIT_VALUE); |
@chadoh I kinda like (3) the most for ergonomics - what're the cons? The implicit sign-ingness? |
They'd still have to approve it via Freighter et al. though, yeah? It's the most implicit for keypairs I guess but I think it's fine 🤷 |
I don't love the idea of being overly smart about it but as long as I have mechanics for overriding requiring the use of G-address signers on Freighter-like wallets I don't care that much. I'm definitely in the camp where we'll start to see more and more use of smart wallets as signers and less and less external G-addresses via extensions, etc. So I will take the line we should plan for that and not assume we really know how folks will want to get these transactions signed or submitted and being too smart will lead to more of the issues we have now where the JS-SDK has to be wrestled against in many cases because it assumes too much. |
Fwiw I don't see the use case being too common that folks will want to deploy and then invoke a contract back to back. There will be more time gaps between those actions. For that reason I think Option 1 is sufficient and the most sane / consistent with other behaviors. If there was something to change it would yeah be renaming |
First, @chadoh, I love that your example contract is an increment contract that doesn't increment! 🤣 For the reasons @kalepail already pointed out, I'd lean toward option 1 or 2, where the signature/sending is still up to the builder's choices. Which is better? 🤷🏻♂️ I would probably disagree a bit with the usefulness of the approach, though. In the stuff I've built (which is mostly silly, tbh), it's been really useful to deploy/init immediately in a single, atomic transaction. The process of using the deployer example to pass in the Then again, if you already know the Wasm hash (and you would have to if you're attempting a deploy/init thing), it's not that big of a hassle to re-deploy if someone "snatches" your uninitialized contract out from under you. That is assuming the only loss in the uninitialized contract is the fee you spent to deploy it. If something is hard-coded in the uninitialized contract that could lead to actual loss for you, (why would you write the contract that way?) then it is obviously a bigger deal. |
The deployer contract was a stop gap measure imo. It adds a layer of abstraction for new users (I have to deploy a contract to deploy my contract?). Now we have a way to do both with the types! Regardless we need to offer this to match the functionality in the CLI. I also think it will be great in the Lab when paired with contract invocation forms. So devs can deploy contracts with documentation and types! |
@ElliotFriend thanks for the review! I'm not sure I understand your concern, though. It sounds like you are saying you disagree with this change (which aspect of it?), but then go on to sing its virtues. "We need easier deploy-and-init!" Well, yes, that's what this is! |
b493046
to
dd0e63a
Compare
This will allow using a wasm hash and constructor args to create an assembled transaction that will deploy and initialize a contract. Generated types in the CLI are to follow.
Uses new branch at stellar/soroban-test-examples#2
Co-authored-by: Elliot Voris <elliot@voris.me>
dd0e63a
to
cbb58a3
Compare
Sticking with Option 1 for now, since it's the simplest to implement/maintain and it seems like maybe it won't matter to many people. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👏
explicit constructorArgs contract went away; it's now part of `increment`
1f0f0c6
to
e7ea8d1
Compare
…ntracts (stellar#1086) This will allow using a wasm hash and constructor args to create an assembled transaction that will deploy and initialize a contract. Generated types in the CLI are to follow. Co-authored-by: Elliot Voris <elliot@voris.me> Co-authored-by: Chad Ostrowski <221614+chadoh@users.noreply.github.com> Co-authored-by: Elliot Voris <elliot@voris.me>
@chadoh Just realized I never responded to your comment!! So sorry! 🤦🏻♂️ What I meant was that I disagree with Tyler on his stance that |
This will allow using a wasm hash and constructor args to create an assembled transaction that will deploy and initialize a contract. Generated types in the CLI are to follow.