Jacob Tucker Profile picture
Mar 29 9 tweets 5 min read Twitter logo Read on Twitter
A huge update is coming to #Cadence, the smart contract language used by @flow_blockchain:

📥Attachments

What are they and how do we code them?
👇🧵 Image
@flow_blockchain 📽️Before I begin, I made a YouTube video diving into attachments here:
@flow_blockchain 1/ What are they?

Attachments are what they sound like: things we can attach to resources and structs in Cadence.

⚔️For example, we can attach a "Pet" or a "Weapon" to any NFT.
@flow_blockchain 2/ Composability

This is insanely cool if you think about it. It represents composability at its finest.

📦You can define your own attachment and place it on *any* resource (like an NFT) that you own. You are literally building on top of pre-defined assets.
@flow_blockchain 3/ How to define them?

In this case, we create an attachment called "Pet" that can be attached to any `NonFungibleToken.NFT` type on @flow_blockchain. Image
@flow_blockchain 4/ How to attach them?

Simply use the `attach` keyword to add an attachment to a type that it can be attached to. Image
@flow_blockchain 5/ How to access an attachment?

We can use bracket notation `[]` to access an attachment on a type. Image
@flow_blockchain 6/ Learn More

Read up on attachments here: github.com/onflow/flips/b…

Watch a video on it here:
@flow_blockchain 7/ Conclusion

Thanks to @C_3PFLO for making a super cool demo here: github.com/C-3PFLO/flow-r…

You inspired me to make this thread! ;)

Follow me for more Cadence tips 🥳

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Jacob Tucker

Jacob Tucker Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @jacobmtucker

Mar 28
In #Cadence, there are 4 phases to a transaction:

1. "Prepare"
2. "Pre"
3. "Execute"
4. "Post"

What are the differences between them?

👇🧵 Image
1. The prepare phase

This is the first part of the transaction to get run.

⚠️It is also the only place you have access to the signer's `AuthAccount`, a type that allows you to have full access to an account.
It is best practice to only use the prepare phase for things that require the `AuthAccount` type, like borrowing a reference to a user's NFT Collection.

You can think of the prepare phase as the "setup" of a transaction. Image
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(