Add import alias support for Cadence contracts#167
Merged
Conversation
jribbink
reviewed
Nov 10, 2025
jribbink
reviewed
Nov 10, 2025
dd2c214 to
794c3b1
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
jribbink
reviewed
Nov 15, 2025
Comment on lines
+305
to
+311
| // // Use with import replacer | ||
| // contracts, _ := state.DeploymentContractsByNetwork(network) | ||
| // aliases := state.AliasesForNetwork(network) | ||
| // replacer := project.NewImportReplacer(contracts, aliases, mapping) | ||
| // | ||
| // // Process imports: "FUSD_v2" → "import FUSD as FUSD_v2 from 0x..." | ||
| func (p *State) CanonicalContractMapping() map[string]string { |
Contributor
There was a problem hiding this comment.
nit: do we need this? feels like practically someone would just use state.Contracts()[idx].Canoncal or equivalent
will it actually be needed for import replacement?
jribbink
approved these changes
Nov 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds import alias support to Flowkit, allowing contracts to be imported under different names while referencing a canonical contract's source code.
Example
flow.json Configuration
{ "contracts": { "FUSD": { "source": "./contracts/FUSD.cdc", "aliases": { "testnet": "0x9a0766d93b6608b7", "mainnet": "0x3c5959b568896393" } }, "FUSD1": { "source": "./contracts/FUSD.cdc", "aliases": { "testnet": "0xe223d8a629e49c68", "mainnet": "0x8d0e87b65159ae63" }, "canonical": "FUSD" }, "FUSD2": { "source": "./contracts/FUSD.cdc", "aliases": { "testnet": "0x0f9df91c9121c460", "mainnet": "0x754a90d51a1c8e1b" }, "canonical": "FUSD" } } }Import Syntax Conversion
Before Processing:
After Processing by Flowkit:
The canonical contract (
FUSD) uses regular import syntax, while alias contracts (FUSD1,FUSD2) use theimport X as Ysyntax, allowing multiple imports of the same contract with different names.