Skip to content

Commit 5dc415f

Browse files
authored
Merge pull request #242 from onflow/imports-option
Add new import option and priortize it
2 parents 7b71f65 + 1a24e0d commit 5dc415f

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

docs/language/imports.mdx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,37 @@ sidebar_position: 15
55

66
Programs can import declarations (types, functions, variables, and so on) from other programs.
77

8-
Imports are declared using the `import` keyword.
8+
## Importing contracts
99

10-
It can either be followed by a location, which imports all declarations; or it can be followed by the names of the declarations that should be imported, followed by the `from` keyword, and then followed by the location.
10+
Imports are declared using the `import` keyword. You can import your contracts using **one** of the following three options:
1111

12-
- If importing a local file, the location is a string literal, as well as the path to the file. Deployment of code with file imports requires usage of the [Flow CLI].
13-
- If importing an external type in a different account, the location is an address literal, as well as the address of the account where the declarations are deployed to and published.
12+
1. Import your contracts by name, which you must use if you're using the [Flow CLI]. For example:
1413

15-
```cadence
16-
// Import the type `Counter` from a local file.
17-
//
18-
import Counter from "./examples/counter.cdc"
14+
```cadence
15+
import "HelloWorld"
16+
```
1917

20-
// Import the type `Counter` from an external account.
21-
//
22-
import Counter from 0x299F20A29311B9248F12
23-
```
18+
This will automatically import the contract, based on the configuration found `flow.json`. It will automatically handle address changes between mainnet, testnet, and emulator, as long as those are present in `flow.json`.
19+
20+
1. Import your contracts by an address, which imports all declarations. Both [Flow playground] and [Flow runner] require importing by address.
21+
22+
1. Import your contracts by the names of the declarations that should be imported, followed by the `from` keyword, and then followed by the address.
23+
24+
- If importing a local file, the location is a string literal, as well as the path to the file. Deployment of code with file imports requires usage of the [Flow CLI].
25+
- If importing an external type in a different account, the location is an address literal, as well as the address of the account where the declarations are deployed to and published.
26+
27+
```cadence
28+
// Import the type `Counter` from a local file.
29+
//
30+
import Counter from "./examples/counter.cdc"
31+
32+
// Import the type `Counter` from an external account.
33+
//
34+
import Counter from 0x299F20A29311B9248F12
35+
```
2436

2537
<!-- Relative links. Will not render on the page -->
2638

27-
[Flow CLI]: https://developers.flow.com/tools/flow-cli/index.md
39+
[Flow CLI]: https://developers.flow.com/tools/flow-cli/index.md
40+
[Flow playground]: https://play.flow.com/
41+
[Flow runner]: https://run.dnz.dev/

0 commit comments

Comments
 (0)