Flow Interaction Templates (FLIX)
FLIX helps developers reuse existing Cadence transactions and scripts to easily integrate with existing Cadence smart contracts. Get more information about Flow Interaction Templates
Introduction
The Flow CLI provides a flix
command with a few sub commands execute
and package
. Get familiar with Flow Interaction Templates (FLIX). FLIX are a standard for distributing Cadence scripts and transactions, and metadata in a way that is consumable by tooling and wallets. FLIX can be audited for correctness and safety by auditors in the ecosystem.
Execute
The Flow CLI provides a flix
command to execute
FLIX. The Cadence being execute in the FLIX can be a transaction or script.
A FLIX template might only support testnet and/or mainnet. Generally, emulator is not supported. This can be the case if the FLIX template relies on contract dependencies.
Queries can be a FLIX id
, name
, url
or path
to a local FLIX file.
Execute Usage
The Flow CLI provides a flix
command to package
up generated plain and simple JavaScript. This JavaScript uses FCL (Flow Client Library) to call the cadence the Flow Interaction Templates (FLIX) is based on.
Currently, flix package
command only supports generating FCL (Flow Client Library) specific JavaScript and TypeScirpt, there are plans to support other languages like golang.
Generate
Generate FLIX json file. This command will take in a Cadence file and produce a FLIX json file. There are two ways to provide metadata to populate the FLIX json structure.
- Use
--pre-fill
flag to pass in a pre populated FLIX json structure - Use
--exclude-networks
flag to specify excluded networks when generating a FLIX templates. Example,--exclude-networks testnet,mainnet
When generating a FLIX template, make sure all contract dependencies have been deployed to the supported networks. Add any aliases to your flow.json that will be needed to populate dependencies. Verify all dependencies have been populated after generating.
Generate Usage
Example of Cadence simple, no metadata associated
Cadence Doc Pragma:
It's recommended to use pragma to set the metadata for the script or transaction. More information on Cadence Doc Pragma FLIP
A pragma is short for "pragmatic information", it's special instructions to convey information to a processor in this case the utility that generates FLIX.
Cadence v0.42.7 supports additional Cadence pragma functionality that FlIX utility can use to generate FLIX. It will support parameters "title" and "description".
The resulting json metadata is extracted from Cadence Doc Pragma
Example of using a prefilled FLIX json file. No need to use Cadence pragma when using a prefilled FLIX json file. This method separates FLIX specific information from the transaction or script Cadence. Use the flow flix generate
command:
Using a pre-filled FLIX template, the cadence can be simple but no metadata accompanies it.
Example of json prefill file with message metadata:
The resulting FLIX json file after generation:
Package
Queries can be a FLIX url
or path
to a local FLIX file. This command leverages FCL which will execute FLIX cadence code. Package files can be generated in JavaScript or TypeScript.
Currently package doesn't support id
, name
flix query.
Package Usage
Example Package Output
Notice that fcl v1.9.0 is needed to use FLIX v1.1 templates
Resources
To find out more about FLIX, see the read the FLIP.
For a list of all templates, check out the FLIX template repository.
To generate a FLIX, see the FLIX CLI readme.
Arguments
- Name:
argument
- Valid input: valid FLIX
Input argument value matching corresponding types in the source code and passed in the same order.
You can pass a nil
value to optional arguments by executing the flow FLIX execute script like this: flow flix execute template.json nil
.
Flags
Arguments JSON
- Flag:
--args-json
- Valid inputs: arguments in JSON-Cadence form.
- Example:
flow flix execute template.script.json '[{"type": "String", "value": "Hello World"}]'
Arguments passed to the Cadence script in the Cadence JSON format.
Cadence JSON format contains type
and value
keys and is
documented here.
Pre Fill
- Flag:
--pre-fill
- Valid inputs: a json file in the FLIX json structure FLIX json format
Block Height
- Flag:
--block-height
- Valid inputs: a block height number
Block ID
- Flag:
--block-id
- Valid inputs: a block ID
Signer
- Flag:
--signer
- Valid inputs: the name of an account defined in the configuration (
flow.json
)
Specify the name of the account that will be used to sign the transaction.
Proposer
- Flag:
--proposer
- Valid inputs: the name of an account defined in the configuration (
flow.json
)
Specify the name of the account that will be used as proposer in the transaction.
Payer
- Flag:
--payer
- Valid inputs: the name of an account defined in the configuration (
flow.json
)
Specify the name of the account that will be used as payer in the transaction.
Authorizer
- Flag:
--authorizer
- Valid inputs: the name of a single or multiple comma-separated accounts defined in the configuration (
flow.json
)
Specify the name of the account(s) that will be used as authorizer(s) in the transaction. If you want to provide multiple authorizers separate them using commas (e.g. alice,bob
)
Gas Limit
- Flag:
--gas-limit
- Valid inputs: an integer greater than zero.
- Default:
1000
Specify the gas limit for this transaction.
Host
- Flag:
--host
- Valid inputs: an IP address or hostname.
- Default:
127.0.0.1:3569
(Flow Emulator)
Specify the hostname of the Access API that will be
used to execute the command. This flag overrides
any host defined by the --network
flag.
Network Key
- Flag:
--network-key
- Valid inputs: A valid network public key of the host in hex string format
Specify the network public key of the Access API that will be used to create a secure GRPC client when executing the command.
Network
- Flag:
--network
- Short Flag:
-n
- Valid inputs: the name of a network defined in the configuration (
flow.json
) - Default:
emulator
Specify which network you want the command to use for execution.
Filter
- Flag:
--filter
- Short Flag:
-x
- Valid inputs: a case-sensitive name of the result property.
Specify any property name from the result you want to return as the only value.
Output
- Flag:
--output
- Short Flag:
-o
- Valid inputs:
json
,inline
Specify the format of the command results.
Save
- Flag:
--save
- Short Flag:
-s
- Valid inputs: a path in the current filesystem.
Specify the filename where you want the result to be saved
Log
- Flag:
--log
- Short Flag:
-l
- Valid inputs:
none
,error
,debug
- Default:
info
Specify the log level. Control how much output you want to see during command execution.
Configuration
- Flag:
--config-path
- Short Flag:
-f
- Valid inputs: a path in the current filesystem.
- Default:
flow.json
Specify the path to the flow.json
configuration file.
You can use the -f
flag multiple times to merge
several configuration files.
Version Check
- Flag:
--skip-version-check
- Default:
false
Skip version check during start up to speed up process for slow connections.