Hello developers,
The Flow core contributors created a tool which you can use to analyze your Cadence contracts for the recently announced breaking changes which will go into affect with the release of Secure Cadence in the next spork.
You can read more about Secure Cadence and the breaking changes here:
Breaking changes coming with Secure Cadence release
NOTE: The analyzer is only able to identify code that might need to change. To verify your changes, use the Secure Cadence beta release of the CLI linked above, and test your code using the Secure Cadence emulator.
Installation
-
On Linux and macOS:
sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install-cadence-analyzer.sh)"
-
On Windows, in PowerShell:
iex "& { $(irm 'https://storage.googleapis.com/flow-cli/install-cadence-analyzer.ps1') }"
Usage
Analyzing contracts of an account
To analyze all contracts of an account, specify the network and address. This requires you have the Flow CLI installed and configured properly (run flow init
).
For example:
cadence-analyzer -network mainnet -address 0x1654653399040a61
Analyzing a transaction
To analyze a transaction, specify the network and transaction ID.
This requires you have the Flow CLI installed and configured (run flow init
).
For example:
cadence-analyzer -network mainnet -transaction 44fd8475eeded90d74e7594b10cf456b0866c78221e7f230fcfd4ba1155c542f
Only running some analyzers
By default, all available analyzers are run.
To list all available analyzers, run:
cadence-analyzer -help
For example, to only run the reference-to-optional
and the external-mutation
analyzers, run:
cadence-analyzer -network mainnet -address 0x1654653399040a61 \
-analyze reference-to-optional \
-analyze external-mutation
Analyzing contracts in a directory
To analyze all contracts in a directory, specify the path.
For example:
cadence-analyzer -directory contracts
The files must be named with the .cdc
extension and by their location ID of the program:
- Contracts in accounts have the format
A.<address>.<name>
,
e.g.A.e467b9dd11fa00df.FlowStorageFees
, whereaddress
: Address in hex format, e.g.e467b9dd11fa00df
name
: The name of the contract, e.gFlowStorageFees
- Transactions have the format
t.<ID>
, whereid
: The ID of the transaction (its hash)
- Scripts have the format
s.<ID>
, whereid
: The ID of the script (its hash)
Analyzing contracts in a CSV file
To analyze all contracts in a CSV file, specify the path to the file.
For example:
cadence-analyzer -csv contracts.csv
The CSV file must be in the following format:
- Header:
location,code
- Columns:
location
: The location ID of the program- Contracts in accounts have the format
A.<address>.<name>
,
e.g.A.e467b9dd11fa00df.FlowStorageFees
, whereaddress
: Address in hex format, e.g.e467b9dd11fa00df
name
: The name of the contract, e.gFlowStorageFees
- Transactions have the format
t.<ID>
, whereid
: The ID of the transaction (its hash)
- Scripts have the format
s.<ID>
, whereid
: The ID of the script (its hash)
- Contracts in accounts have the format
code
: The code of the contract, e.g.pub contract Test {}
Full example:
location,code
t.0000000000000000,"
import 0x1
transaction {
prepare(signer: AuthAccount) {
Test.hello()
}
}
"
A.0000000000000001.Test,"
pub contract Test {
pub fun hello() {
log(""Hello, world!"")
}
}
"