flow-cli icon indicating copy to clipboard operation
flow-cli copied to clipboard

Enable adding a contract from mainnet or testnet

Open bjartek opened this issue 3 years ago • 7 comments

Instructions

When writing transactions and scripts you often want to include standard contracts in them. The best way to do this is to download the files locally and add them as contracts in flow.json with the corresponding testnet/mainnet aliases.

It would be nice if there was support for doing this using the flow cli.

Issue To Be Solved

I want to use NonFungibleToken contract interface in my trnasactions using the relative file import.

It is also applicable for any other contract on mainnet or testnet.

(Optional): Suggest A Solution

Add support for donwloading a contract from mainnet into a folder of your choice (default contracts) and add the corresponding information to flow.json

example: flow config add contract --network mainnet --account 0xd796ff17107bbff6 Profile

This should fetch the Profile contract from Versus into contracts/Profile.cdc and add that information to flow.json

bjartek avatar Jul 21 '21 20:07 bjartek

This would be great.

Letting users automatically download arbitrary code they didn't write comes with a requisite conversation about security subsystems. So here goes.

The great thing about Cadence is it's relatively easy to audit, once you have the source files. But, it's likely not a sufficient security guarantee.

I wonder, if we did end up implementing this, if we could track which code is getting reused the most and aggregate some kind of trust metric for specific accounts and contracts?

10thfloor avatar Jul 21 '21 20:07 10thfloor

Adding telemetry/obersvability would be a great boost here.

What i deally would like to do is:

  • download a contract from testnet with a given account/name or mainnet.
  • add the relevant aliases to flow.json
  • add the contract to emulator-account deployment (if a extra flag is added)

All this (except adding main network alias) is possible using flow today with some jq sugar.

Bash script to download a contract.

#!/bin/env bash

[[ $# -ne 2 ]] && echo "Usage: $0 <account> <contract>" &&  exit 1

flow accounts get $1 -n mainnet --include contracts -o json | jq --arg a "$2" '.code[$a]' -r > $2.cdc

bjartek avatar Jul 21 '21 20:07 bjartek

Also you could add an option in the vscode extention to automatilly download a contract from mainnet if you use a old style address import.

bjartek avatar Jul 21 '21 20:07 bjartek

I will link to a closed issue where we also talked about a similar feature: https://github.com/onflow/flow-cli/issues/71

I think that some kind of a "contract fetching" functionality would be good. When I'm thinking about this I'm thinking about npm and how it downloads the modules and links them. I think something similar could be good, but to support syntax that will be future proof, so to support different locations (flow, git,...).

devbugging avatar Jul 22 '21 07:07 devbugging

Ok with me.

bjartek avatar Jul 22 '21 08:07 bjartek

We had a brainstorming session in office hours which produced an idea of supporting multiple contract registries. The registry could be denoted by the new import schema and the flowkit part of the CLI could define support for different registries. There should be a defined interface that could be implemented for each registry and it would also contain a prefix you would then use in the import schema to say where you want to fetch the contract. An example would be: @onflow/FungibleToken.cdc which would use the implemented onflow registry resolver. Similarly, there could be any community maintained registry added to this list.

devbugging avatar May 13 '22 10:05 devbugging

Hello! Apologies for resurrecting an old thread, but I had recently worked on: https://github.com/jrkhan/cadence-import (a Cobra CLI tool for importing Cadence contracts from testnet/mainnet) and have been given feedback that it might be a good fit for the FlowCLI. While it doesn't address the issue of a public registry yet, I was hoping to have it make use of the Flow NFT Catalog in the near future. The other thing I'm aware it doesn't handle yet, would be contracts with overlapping names. Was wondering if it you would be open to reviewing a PR to add this as a command, or otherwise had any questions/comments/concerns?

jrkhan avatar Sep 21 '22 17:09 jrkhan

I have a proposal covering the need here: https://github.com/onflow/flow-cli/issues/929 Please check and comment! @bjartek @jrkhan

nvdtf avatar Mar 30 '23 01:03 nvdtf

Closing this in favour of https://github.com/onflow/flow-cli/issues/929

devbugging avatar Apr 11 '23 10:04 devbugging