Error in Scope While Importing From Local File

Hey all - me and my team are new to flow - and having a bit of trouble with creating our own smart contracts. We are trying to follow along with the developer tutorial - but we are current stuck when trying to import a public contract from another local file. We receive the following error:

INFO[0956] ⭐  Transaction executed                       txID=150a23a2841430ee88d6e3122b78fe69162ac6ac4dcc4c6a2b7cab3b981aee6a
WARN[0956] ❗  Transaction reverted                       txID=af2be854035f27b38ce5bf8cd2ddc8ecb585d86a0286424ea80518b5726ae1f3
WARN[0956] ERR [af2be8] Execution failed:
error: cannot deploy invalid contract
  --> af2be854035f27b38ce5bf8cd2ddc8ecb585d86a0286424ea80518b5726ae1f3:11:3
   |
11 | 			acct.contracts.add(name: contract, code: contracts[contract]!.decodeHex())
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot find type in this scope: `FungibleToken`
 --> e03daebed8ca0615.EngramToken:3:26
  |
3 | pub contract EngramToken: FungibleToken {
  |                           ^^^^^^^^^^^^^ not found in this scope

EngramToke.cdc has:

import FungibleToken from "./FungibleToken.cdc"

pub contract EngramToken: FungibleToken {
}

And FungibleToken.cdc has:

pub contract interface FungibleToken {
    ....
}

Both .cdc files live within the same folder level.

I noticed while reading the docs here: link that:

Status: Imports from local files are not currently implemented.

Could this be the reason for our import error?

Just curious if anyone has run into a similar issue. Thanks!

Hi John!

The CLI now supports deploying contracts using file names, it deploys the contracts and rewrites the imports to the addresses where the imported contracts were deployed to. Are you using this feature?

I’ll update the outdated status note in the documentation.

Hi John,

you can import contracts from a local file just make sure you use Flow CLI project functionality.

You can read more about it here: Deploy a Flow Project - Flow Documentation

But explained simply you need to create flow.json file in which you specify your improts and location where that files are and then run flow project deploy.

Your flow.json will probably look like:

{
  // ... other content in the flow.json - generate it by running: flow init
  "contracts": {
    "EngramToken": "location to your contract",
    "FungibleToken": "./cadence/contracts/FungibleToken.cdc"
  },
  "deployments": {
    "emulator": {
      "emulator-account": ["FungibleToken", "EngramToken"]
    }
  },
  ...
}

Thank you @sideninja and @turbolent ! You guys were right on the money - we weren’t using a flow project - rather just running the go code using the go tools directly.

We changed the code to use dynamic references for now - and will migrate it to use a Flow CLI project soon.

Thank you for your replies!