Flow CLI as a development tool

I’m starting to put some more thought into how the CLI could be better designed as a development tool and not just a utility to query the chain. I’m specifically interested in streamlining the local development workflow with the emulator.

Contract deployment and account management are two of the biggest pain points I’m seeing with both local (emulator) and testnet development. I think it’d be great if the CLI included better tooling to map contracts to accounts, especially when using the same contracts on multiple networks (emulator and testnet) or with multiple accounts on the same network.

I sketched out some ideas in this issue: Automated contract deployment · Issue #30 · onflow/flow-cli · GitHub

Yes! Eric and I have something a little bit more primitive then this in go-with-the-flow.

As a side note please add support in vscode extension to help manage this. Like «add a new contract to account» aso.

Also the ability to compose a scenario like we do here would be lovely auction-flow-contract/main.go at master · versus-flow/auction-flow-contract · GitHub

1 Like

I have a draft PR up that adds a new deploy-contracts command. Feedback is welcome! Add deploy-contracts command by psiemens · Pull Request #45 · onflow/flow-cli · GitHub

Regarding Initialize a Flow Project - Flow Documentation

  • in the Configuration example the souce for FungibleToken is NonFungibleToken
    • also Fungible token is always present just under different addresses
  • NonFungibleToken is not there on emulator, but it is there on mainnet and testnet
  • Under user and admin account there is a keys option. That looks like it is a private key
    • it would be nice if this key could be specified in a file outside of the project root. So say $HOME/.flow–.json and be configurable with an ENV var. FLOW_TESTNET_JSON_PATH or something like that
    • ideally this flow.json file should be checked in with the code, but not the pks on testnet/mainnnet
  • filling out the address for mainnet would be nice
  • filling out the addresses for other contracts that are available on testnet/mainnet like the CORE flow contracts would also be nice
    • also reusing contracts across projects would be nice, so what about beeing able to specify the url to the contracts as an URL?
1 Like

Thank you for the feedback!

Under user and admin account there is a keys option. That looks like it is a private key
it would be nice if this key could be specified in a file outside of the project root. So say $HOME/.flow–.json and be configurable with an ENV var. FLOW_TESTNET_JSON_PATH or something like that
ideally this flow.json file should be checked in with the code, but not the pks on testnet/mainnnet

@sideninja actually created an issue related to this today! Separate configuration for private accounts · Issue #70 · onflow/flow-cli · GitHub

also reusing contracts across projects would be nice, so what about beeing able to specify the url to the contracts as an URL?

And this one, too! Great minds think alike :slight_smile: Import and deploy contracts from remote sources · Issue #71 · onflow/flow-cli · GitHub

in the Configuration example the souce for FungibleToken is NonFungibleToken
also Fungible token is always present just under different addresses
NonFungibleToken is not there on emulator, but it is there on mainnet and testnet

Thank you for noticing, this is fixed in PR #73.

I’m inviting you to share more of your good ideas on the issues you mentioned with the configuration keys.

What about contracts with init arugments? Should there be a default template for applying the contract and the posibility to use a custom one?

This ties neatly into the next enhancement, creating accounts that does not have contracts with them but that can be used for running transactions. Kinda like generate a new key, create an account for that key and add those to flow.json under a given name.

Then there is the problem of how do you specify an transaction? Make create a seperate json schema for how to specify a transaction? Read from a file/url and specify a list of arguments with a given type? One of the types could be an alias to an argument?

Also it would be nice if the option to run these contracts and apply projects could optionally emit things to stdout and read from stdin, so that they can be composed in a nice unix way.

And finally, I am willing to help. :slight_smile:

2 Likes

Adding some commands to modify that flow.json would be nice.

  • add a new contract under a given name from a path
  • generate a key for a given account and populate it for a given chain
1 Like

@sideninja actually gave some thought to this already. Made an issue here: Deploy contracts with initializer arguments · Issue #79 · onflow/flow-cli · GitHub

This ties neatly into the next enhancement, creating accounts that does not have contracts with them but that can be used for running transactions. Kinda like generate a new key, create an account for that key and add those to flow.json under a given name.

We definitely want this! I think this issue covers it: Improve account management · Issue #31 · onflow/flow-cli · GitHub

Then there is the problem of how do you specify an transaction? Make create a seperate json schema for how to specify a transaction? Read from a file/url and specify a list of arguments with a given type? One of the types could be an alias to an argument?

For this, I was thinking we could start simple and just update the flow transactions send command to hook into the new contract address resolution code. For example, if a transaction imports a contract by file, the CLI could use flow.json to map that file to the correct address before preparing and signing the transaction.

Transaction arguments is a separate task, IMO: Transaction arguments · Issue #36 · onflow/flow-cli · GitHub

Also it would be nice if the option to run these contracts and apply projects could optionally emit things to stdout and read from stdin, so that they can be composed in a nice unix way.

Great idea. How do you think the inputs/outputs should be formatted? These issues might be of interest to you:

And finally, I am willing to help. :slight_smile:

Music to my ears!!

I think that is a great idea. I was thinking to also enable different output serialization like JSON format and enable optional flags to just extract a single data from the output.

Example would be:
accounts get 0x123 --balance

20

This way it can become even easier to compose commands.

This ties neatly into the next enhancement, creating accounts that does not have contracts with them but that can be used for running transactions. Kinda like generate a new key, create an account for that key and add those to flow.json under a given name.

I agree. We should also have a single command to do all you said.

I would really like it if we can work together on some of the features.

regarding outputs, supporting go-template like they do in say kubectl would be a no brainer, since it is so easy to implement with go.

I think supporting both verbose and less verbose json would be interesting.

On GWTF we use this to parse events that does not retain type information go-with-the-flow/event.go at master · bjartek/go-with-the-flow · GitHub

Another command that would be nice to have would be to add a contract to the flow.json.

flow project add-contract <filePath|url> or something like that to add a emulator contract.

@bjartek I’m currently working on a CLI refactor and it will hopefully make things more consistent and output will have a unified structure. I was planning to support templates as well yes.

Add contract command should totally be added. I actually have started an issue about that here: Project manipulation commands · Issue #88 · onflow/flow-cli · GitHub but didn’t yet have the time to implement it.

I agree 100%.

1 Like