Skip to content

Add import alias support for Cadence contracts#167

Merged
jribbink merged 11 commits intomainfrom
feature/import-aliasing-support
Nov 18, 2025
Merged

Add import alias support for Cadence contracts#167
jribbink merged 11 commits intomainfrom
feature/import-aliasing-support

Conversation

@chasefleming
Copy link
Member

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:

import "FUSD"
import "FUSD1" 
import "FUSD2"

After Processing by Flowkit:

import FUSD from 0x9a0766d93b6608b7
import FUSD as FUSD1 from 0xe223d8a629e49c68
import FUSD as FUSD2 from 0x0f9df91c9121c460

The canonical contract (FUSD) uses regular import syntax, while alias contracts (FUSD1, FUSD2) use the import X as Y syntax, allowing multiple imports of the same contract with different names.

@chasefleming chasefleming force-pushed the feature/import-aliasing-support branch from dd2c214 to 794c3b1 Compare November 12, 2025 21:06
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 92.50000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
project/imports.go 78.94% 3 Missing and 1 partial ⚠️
state.go 66.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 jribbink merged commit c991c99 into main Nov 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants