onflow / onflow/flow-cli

[Epic] New Contract Dependency Manager

Open
#929 20 comments 1 reaction 2 assignees View on GitHub

@chasefleming is already working on this.

Since Oct 3, 2023.

Feature
Dominant language
Go
Stars
209
Forks
87
Avg merge
1d 17h
Merged PRs (30d)
3

Description

Overview

Following the declarative design principles of Flow CLI we want to build a simple dependency manager that enables developers to:

  • Import a known contract from supported locations such as Flow networks (mainnet, testnet, …), GitHub repositories, or the NFT Catalog into the current project.
  • Deliver code with dependencies without re-shipping copies of dependencies.
  • Checkout missing dependencies based on flow.json

Design

Each contract is identified in flow.json by a unique identifier. It can be imported into another contract, transaction, or script like this:

import "MyContract"

The pre-processor will replace the imports with valid Cadence syntax and addresses based on flow.json:

"contracts": {
	"MyContract": "./contracts/MyContract.cdc", // local file location
	"TopShot": "mainnet/0x0123123123/TopShot", // live network address
	"NonFungibleToken": "github.com/onflow/flow-nft/NonFungibleToken.cdc", // github
	"CoolNFT": "nft-catalog/mainnet/CoolNFT"
}

The simple syntax can be evolved in the future to support specific commit hashes or versions for GitHub, or block heights for addresses.
Flow CLI will support checking for missing dependencies and checking them out into a local imports folder. The folder can be added to .gitignoreso other developers always pull the dependencies from the original source-of-truth.

flow contracts install

Flow CLI can check all dependencies and fetch missing ones into imports with this command:

flow contracts install
flow contracts add
  • From live Flow networks:
flow contracts add mainnet/0x0123123123/TopShot

A copy of the contract is fetched into the imports folder. For each import, a subfolder is created and the same operation is executed recursively. An alias entry is also created in flow.json to prevent re-deployments. Check out
cadence-import to see this in action.

  • From NFT Catalog:
flow contracts add nft-catalog/mainnet/CoolNFT

The contract address is resolved via NFT Catalog. The same steps as importing from networks are applied.

  • From GitHub:
flow contracts add github.com/onflow/flow-nft/NonFungibleToken.cdc

A copy of the contract is fetched into the imports folder from the latest commit. The name of the contract will be resolved from the contents. If the contract has imports, the repository’s root flow.json is checked to resolve them.

### Issues
- [ ] #910 
- [ ] #331 
- [ ] #944
- [ ] #957
- [ ] #958 

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.