flow-playground icon indicating copy to clipboard operation
flow-playground copied to clipboard

Feature: Add support for specifying arguments to smart contract initializers

Open joshuahannan opened this issue 4 years ago โ€ข 6 comments

Is your feature request related to a problem? Please describe. Smart contracts can have arguments to their initializers, but we cannot submit arguments as part of contract deployment in the playground UI.

Describe the solution you'd like When deploying a contract, a box with argument boxes could pop up and a user could type in the arguments for the init function.

joshuahannan avatar Jun 01 '20 18:06 joshuahannan

Oh nice. This is obviously a common pattern?

10thfloor avatar Jun 02 '20 21:06 10thfloor

I wouldn't say it is super common, but it is something that is useful to be able to do and will be encountered somewhat often. Definitely worth discussing how we want to include it

joshuahannan avatar Jun 02 '20 21:06 joshuahannan

It would be useful when for example- token contracts have a fixed total supply and they want to initialize it by passing an arument to the contract's init function. Same for any contracts that want to define variable values dynamically at contract initialization.

rahul-kothari avatar Jun 03 '20 09:06 rahul-kothari

This could be implemented in a similar fashion to #29. Arguments could be specified before clicking the "Deploy" button, similar to the "Send" button for transactions.

psiemens avatar Aug 04 '20 21:08 psiemens

@MaxStalker is blocked until he can get some help from @turbolent and @psiemens to get arguments accepted on server side

timmymmit avatar Nov 18 '20 18:11 timmymmit

@psiemens @turbolent Is the API ready for this?

10thfloor avatar Jan 29 '21 19:01 10thfloor

@bthaile I just discovered a bug related to this. When trying to deploy a contract with an init argument, the contract doesn't report an error and also doesn't deploy the contract. it just returns to the same state from before the deployment without giving any information.

You can reproduce by creating a new project, adding any argument to HelloWorld's init method, then clicking Deploy.

joshuahannan avatar May 12 '23 15:05 joshuahannan

I assume the answer is Yes, but does emulator support passing in arguments when deploying contracts?

bthaile avatar May 30 '23 21:05 bthaile

@bthaile yap,yap :) You can check example (and the whole series as well ๐Ÿ˜‰) here: https://dev.to/onflow/build-on-flow-js-testing-2-setup-emulator-and-deploy-contracts-38l6

MaxStalker avatar May 30 '23 21:05 MaxStalker

More I look into it, maybe the Language Server isn't returning the "executionArguments" when process the contract.

bthaile avatar May 30 '23 21:05 bthaile

@bthaile oh, wait - you mean on Playground? ๐Ÿ˜…

MaxStalker avatar May 30 '23 21:05 MaxStalker

Yes, looking at playground. Which uses cadence language server to parse code. Looks like cadence tools does support finding contract init arguments. At least found this test

https://github.com/onflow/cadence-tools/blob/2dd0a849291ab0277765798d039982f50e102ec8/languageserver/test/index.test.ts#L175

      const args = await languageClient.sendRequest(
        ExecuteCommandRequest.type,
        {
          command: 'cadence.server.getEntryPointParameters',
          arguments: [editor.getModel().uri.toString()],
        },
      );

Adding init parameter

   ...
    init(message: String) {
        self.greeting = message
    }
   ...

LS returns args is empty for contracts

Side Note: playground api needs to add arguments to CreateContractDeployment parameters.

bthaile avatar May 30 '23 21:05 bthaile

I found the issue, there is a separate command for getting contract initialization parameters. cadence.server.getContractInitializerParameters playground wasn't using it.

Downside there isn't a cadence.server.parseEntryPointArguments for contract initialization parameters, this seems like lacking functionality.

https://github.com/onflow/cadence-tools/blob/2dd0a849291ab0277765798d039982f50e102ec8/languageserver/server/server.go#L282

bthaile avatar Jun 02 '23 21:06 bthaile

Changes have been made to Cadence Language server. Next will be updating the API to take in arguments.

bthaile avatar Jun 12 '23 16:06 bthaile