Questions tagged [onflow-cadence]

Cadence is a smart contract language primarily for the Flow blockchain. Use this tag for questions about programming smart contracts using the Cadence language.

Cadence is a resource-oriented programming language that introduces new features to smart contract programming that help developers ensure that their code is safe, secure, clear, and approachable.

57 questions
1
vote
1 answer

How do you make a resource self-destruct on flow / cadence?

I would like for a resource to have a function where at the end of the function it self destructs by calling destroy self pub resource SelfDestructingConsumable { pub fun consume() { // do some stuff destroy self } } The type checker…
Aylii
  • 525
  • 4
  • 10
1
vote
1 answer

Bug "Error: INVARIANT mutate({ cadence }) -- cadence is required"

I happen this bug when I get getAccount from BE. How to resolve it?
1
vote
1 answer

Flow testnet getting: An error occurred when interacting with the Access API

I'm trying to make a request to the testnet but getting the following error: HTTP Request Error: An error occurred when interacting with the Access API. transport=FetchTransport error=Failed to fetch hostname=access.devnet.nodes.onflow.org:9000…
codhur_jones
  • 153
  • 9
1
vote
2 answers

Reference types in Cadence

I have been messing around with types, specifically reference types, using the flow playground ft tutorial and I came up with a doubt. References are supposed to have their own type, a reference to the referenced resource type; e.g for a…
alilloig
  • 456
  • 1
  • 4
  • 11
1
vote
1 answer

View an Account’s Storage

Is there a way to query an AuthAccount’s storage? For example, to see all of the resources stored under the /storage/... domain. I’m fairly new to Flow, but from what I have gathered there is no real way to query or check all of the saved paths in…
1
vote
1 answer

How to indent flow/cadence files in vim correctly

In cadence a resource interface can contain state and methods that needs to be implemented. However when I try to indent a cadence file in vim it will indent the code wrong. pub resource interface INFT { pub let id: UInt64 pub fun getName():…
bjartek
  • 929
  • 1
  • 5
  • 11
1
vote
1 answer

exec: "code": executable file not found in $PATH

I am trying to download a VSCode extension in order to be able to use cadence in VSCode, but when I type: flow version and then: flow cadence install-vscode-extension into the command line, I keep getting this error: exec: "code": executable file…
cluelesscoder
  • 35
  • 1
  • 5
0
votes
1 answer

I'm having trouble receiving these values with a script

I have simple resource with two Int variable and a string array. I want to write seperate scripts to retrieve each variable in a resource. this is the resource i have. pub resource State{ pub var Name: String pub var P: Int …
0
votes
0 answers

Problem with onflow nft-catalog Example 5

I'm trying to use the first script from example 5 here https://github.com/onflow/nft-catalog but it throws an error This is the code import MetadataViews from 0x1d7e57aa55817448 import NFTCatalog from 0x49a7cda3a1eecc29 import NFTRetrieval from…
user100911
  • 15
  • 5
0
votes
0 answers

Flow Blockchain - Single Smart Contract to manage multiple template-based Smart Contracts

My goal is to manage different smart contracts (which are created from the same template contract, just replaced name, paths,etc) with a single, sort of, Registry Smart Contract. Only people who have admin resource of Registry contract is able to…
0
votes
3 answers

Error: value of type &NftMarketPlace.saleCollection{NftMarketPlace.saleCollectionPublic}? has no member purchase

let payment <- acct.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)!.withdraw(amount: price) as! @FlowToken.Vault saleCollection.purchase(id: id, receipientCollection: recipientCollection, payment: <- payment) } my whole cadence code…
Wiswa
  • 11
  • 2
0
votes
1 answer

How can I retrieve a value from a resource in a resource rather than the uuid?

here's the contract that has the resource in the resource pub resource interface InventoryPublic{ pub var items: @{UInt64: Grocery} } pub resource Inventory: InventoryPublic{ pub var items: @{UInt64: Grocery} pub…
0
votes
1 answer

Find account address given public key

Is there a command on the Flow CLI that will allow me to input a public key and the command will output the account address associated with that key? flow accounts get --network mainnet --output json
RMT Books
  • 19
  • 2
0
votes
1 answer

Can a byte array be converted to an Address in Cadence

Is there way to construct an Address from a byte array of UInt8 in Cadence? Docs have this example: let someAddress: Address = 0x436164656E636521 someAddress.toBytes() What I've tried: let hexStr = String.encodeHex([0,0,0,0,0,0,0,1]) let addrStr =…
Gurra
  • 5
  • 2
0
votes
1 answer

In Cadence smart contract programming language, what distinguishes pre/post conditions from assert statements?

Pre and post-conditions are considered pure conditions, as they prohibit any state mutative operations. Similarly, assert statements also do not allow state mutative operations. However, there remains a key distinction between the two. As a…