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

script execution does not resolve contract address from config source

Open j1010001 opened this issue 2 years ago • 5 comments

Problem

Executing simple script like this:

import FungibleToken from "cadence/contracts/FungibleToken.cdc" import FlowToken from "cadence/contracts/FlowToken.cdc"

pub fun main(address: Address): UFix64 { let acct = getAccount(address) let vaultRef = acct.getCapability(/public/flowTokenBalance)!.borrow<&FlowToken.Vault{FungibleToken.Balance}>() ?? panic("Could not borrow Balance reference to the Vault") return vaultRef.balance }

fails with a following error when the command is not run from the same directory where the script is located: % flow scripts execute -n localnet ./code/simple_script.cdc 0xe9dd1081676bbc90 ❌ Command Error: import cadence/contracts/FungibleToken.cdc could not be resolved from the configuration

When I execute the same script from the directory wher eit is located it succeeds: % flow scripts execute -n localnet ./simple_script.cdc 0xe9dd1081676bbc90 Result: 9999.90100000

Context

Cli version: Version: v0.28.3 The command was run agains a localnet

j1010001 avatar Oct 28 '21 21:10 j1010001

CLI config:

~/flow.json

{ "emulators": { "default": { "port": 3569, "serviceAccount": "emulator-account" } }, "contracts": { "FungibleToken": { "source": "cadence/contracts/FungibleToken.cdc", "aliases": { "localnet": "0xee82856bf20e2aa6", "emulator": "0xee82856bf20e2aa6", "testnet": "0x9a0766d93b6608b7" } }, "FlowToken": { "source": "cadence/contracts/FlowToken.cdc", "aliases": { "localnet": "0x0ae53cb6e3f42a79", "emulator": "0x0ae53cb6e3f42a79", "testnet": "0x7e60df042a9c0868" } } }, "networks": { "localnet": "127.0.0.1:3569", "emulator": "127.0.0.1:3569", "mainnet": "access.mainnet.nodes.onflow.org:9000", "testnet": "access.devnet.nodes.onflow.org:9000" }, "accounts": { "emulator-account": { "address": "f8d6e0586b0a20c7", "key": "ce24192bb86cd7b5ffd0f41abc47f597488cea8a489280dda6d84371764ad52a" }, "localnet-service-account": { "address": "f8d6e0586b0a20c7", "key":{ "type": "hex", "index": 0, "signatureAlgorithm": "ECDSA_P256", "hashAlgorithm": "SHA2_256", "privateKey": "8ae3d0461cfed6d6f49bfc25fa899351c39d1bd21fdba8c87595b6c49bb4cc43" } } }, "deployments": {} }%

j1010001 avatar Oct 28 '21 21:10 j1010001

Update https://github.com/onflow/flow-go/tree/master/integration/localnet#running-a-cadence-script to use the config source once this is resolved.

j1010001 avatar Oct 28 '21 21:10 j1010001

This is related to: https://github.com/onflow/cadence/issues/1132

Probably I can check this next week, if someone else not taking

bluesign avatar Oct 30 '21 12:10 bluesign

@bluesign Hi! is the local file resolution from https://github.com/onflow/cadence/issues/1132 ever implemented in cadence? Or is a specific fix needed in the cli? Thanks!

sukantoraymond avatar May 03 '22 17:05 sukantoraymond

@sukantoraymond I totally forgot that, but I think it can be in CLI ( LS should have the code , so basically just using that also can be ok )

bluesign avatar Aug 03 '22 08:08 bluesign

This should be fixed.

sideninja avatar Feb 09 '23 17:02 sideninja