You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/language/imports.mdx
+27-13Lines changed: 27 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,23 +5,37 @@ sidebar_position: 15
5
5
6
6
Programs can import declarations (types, functions, variables, and so on) from other programs.
7
7
8
-
Imports are declared using the `import` keyword.
8
+
## Importing contracts
9
9
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:
11
11
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.Importyourcontractsbyname, whichyoumustuseifyou're using the [Flow CLI]. For example:
14
13
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
+
```
19
17
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.Importyourcontractsbyanaddress, whichimportsalldeclarations. Both [Flowplayground] and [Flowrunner] requireimportingbyaddress.
- 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.
0 commit comments