Skip to content

Commit d32a4ae

Browse files
authored
Merge pull request #1593 from onflow/cf/import-aliasing-docs
Add import aliasing docs
2 parents 5f9a326 + c80a155 commit d32a4ae

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

docs/build/tools/flow-cli/flow.json/configuration.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,42 @@ Use aliases when contracts are already deployed on specific networks:
155155
- To avoid redeploying dependencies
156156
- To use the official versions of common contracts
157157

158+
#### Cadence Import Aliasing
159+
160+
When deploying the same contract to multiple addresses with different names, use the `canonical` field to reference the original contract. This allows you to import multiple instances of the same contract with different identifiers.
161+
162+
```json
163+
"contracts": {
164+
"FUSD": {
165+
"source": "./contracts/FUSD.cdc",
166+
"aliases": {
167+
"testnet": "0x9a0766d93b6608b7"
168+
}
169+
},
170+
"FUSD1": {
171+
"source": "./contracts/FUSD.cdc",
172+
"aliases": {
173+
"testnet": "0xe223d8a629e49c68"
174+
},
175+
"canonical": "FUSD"
176+
}
177+
}
178+
```
179+
180+
Flow CLI automatically transforms imports for aliased contracts:
181+
182+
```cadence
183+
import "FUSD"
184+
import "FUSD1"
185+
```
186+
187+
Becomes:
188+
189+
```cadence
190+
import FUSD from 0x9a0766d93b6608b7
191+
import FUSD as FUSD1 from 0xe223d8a629e49c68
192+
```
193+
158194
### Deployments
159195

160196
The `deployments` section defines which contracts get deployed to which accounts on which networks.
@@ -201,7 +237,7 @@ Here's a complete `flow.json` for a project with multiple contracts and networks
201237
"testnet": "access.devnet.nodes.onflow.org:9000",
202238
"mainnet": "access.mainnet.nodes.onflow.org:9000"
203239
},
204-
240+
205241
"accounts": {
206242
"emulator-account": {
207243
"address": "f8d6e0586b0a20c7",
@@ -212,7 +248,7 @@ Here's a complete `flow.json` for a project with multiple contracts and networks
212248
"key": "12332967fd2bd75234ae9037dd4694c1f00baad63a10c35172bf65fbb8ad1111"
213249
}
214250
},
215-
251+
216252
"contracts": {
217253
"FungibleToken": {
218254
"source": "./cadence/contracts/FungibleToken.cdc",
@@ -224,7 +260,7 @@ Here's a complete `flow.json` for a project with multiple contracts and networks
224260
"MyToken": "./cadence/contracts/MyToken.cdc",
225261
"MyNFT": "./cadence/contracts/MyNFT.cdc"
226262
},
227-
263+
228264
"deployments": {
229265
"emulator": {
230266
"emulator-account": ["FungibleToken", "MyToken", "MyNFT"]

0 commit comments

Comments
 (0)