onflow/cadence-tools

[LS] getAuthAccount is not supported

justinbarry opened this issue · 11 comments

Problem

image

Steps to Reproduce

Open a cadence script and attempt to use the built in getAuthAccount function.

Acceptance Criteria

No more red squiggly line.

Context

Using version v0.7.1 of the Cadence extension.

image

I think this might be more of a Language Server issue, but I'll look into it.

You can't access getAuthAccount in scripts, you can only do that in transactions https://docs.onflow.org/cadence/language/accounts/#authaccount

@sideninja on scripts you can now, deployed to mainnet on last spork

Whaaat 😮 ohh I'm so sorry for missing this. Reopening then.

We also need to update the docs then. Will issue it up.

The getAuthAccount function is only defined in scripts. The language server would need to know if the given document is a transaction or script to declare the function or not.

You can't access getAuthAccount in scripts, you can only do that in transactions https://docs.onflow.org/cadence/language/accounts/#authaccount

Hi @sideninja I tried the get getAuthAccount in transaction.but didn't succeed.

Getting the error
let acct = getAuthAccount(0x8469322b1f3482d1)
| ^^^^^^^^^^^^^^ not found in this scope

This is my code
export const setupUserTx = `
import MyNFT from 0x8469322b1f3482d1
import NonFungibleToken from 0x631e88ae7f1d7c20
import FungibleToken from 0x9a0766d93b6608b7
import FlowToken from 0x7e60df042a9c0868
import NFTMarketplace from 0x8469322b1f3482d1

transaction {
prepare(acct:AuthAccount) {

 **let acct = getAuthAccount(0x8469322b1f3482d1)**
acct.save(<- MyNFT.createEmptyCollection(), to: /storage/MyNFTCollection)
acct.link<&MyNFT.Collection{MyNFT.CollectionPublic, NonFungibleToken.CollectionPublic}>(/public/MyNFTCollection, target: /storage/MyNFTCollection)
acct.link<&MyNFT.Collection>(/private/MyNFTCollection, target: /storage/MyNFTCollection)

let MyNFTCollection = acct.getCapability<&MyNFT.Collection>(/private/MyNFTCollection)
let FlowTokenVault = acct.getCapability<&FlowToken.Vault{FungibleToken.Receiver}>(/public/flowTokenReceiver)

acct.save(<- NFTMarketplace.createSaleCollection(MyNFTCollection: MyNFTCollection, FlowTokenVault: FlowTokenVault), to: /storage/MySaleCollection)
acct.link<&NFTMarketplace.SaleCollection{NFTMarketplace.SaleCollectionPublic}>(/public/MySaleCollection, target: /storage/MySaleCollection)

}

execute {
log("A user stored a Collection and a SaleCollection inside their account")
}
}

@ashlinSajan what tool you used to write the code? VSCode, Playground...?

@ashlinSajan what tool you used to write the code? VSCode, Playground...?

I actually use the flow cli to deploy my contracts and is using the react frontend to interact with the transaction code added above.

@ashlinSajan what tool you used to write the code? VSCode, Playground...?

UI_bug
The error I received in the frontend from the transaction code

getAuthAccount is available only in scripts, you should use acct from prepare(acct:AuthAccount) to access authorizers.