12. NFTs | Encoding

NFTs

  • Stands for Non Fungible Token

    • 1 token is unique from all others

  • Based on ERC-721 standard

  • Contains a TokenURI

    • Returns a JSON object that contains metadata of NFT

    • JSON contains an image part which contains url of the image

      • This URL can be hosted on chain or IPFS or whereever


Pinata

  • It is a paid service which helps us pin our NFT data

  • It is centralized (not recommended)


NFT.Storage

  • Free storage to Pin our NFT Data

  • Based on FileCoin Blockchain

  • It is decentralized hence


Encoding & Opcodes

  • When we send a transaction, it is compiled down to bytecode and sent in data object of transaction

    • When a contract is created, its block's to address is null

  • EVM reads the bytecode using a reader

    • Each alphabet in the bytecode corresponds to an optcode instruction like 00 means HALT

abi.encode && abi.encodePacked

  • It is a globally available method of solidity

Use Case : String Concatenation

  • It returns a byte object

  • In versions ^0.8.12, we can do string.concat(stringA, stringB)

Use Case : Others

  • Can encode anything to its binary

  • Normal encode method takes a lot of memory i.e initial zeros, hence, we use encodePacked which sorts of works like a compressor

  • TypeCasting works similar but somewhat different behind the scenes

abi.decode

  • We can also decode stuff

  • We can also do multi decoding

  • In order to decode packed objects, we must cast


Encoding Function Calls

call

  • We use call functions to change the state of the blockchain

  • In our {}, we are able to pass specific fields of transactions like value

  • In our (), we can pass data to call a specific function

Withdraw Use Case

We used call with data field empty to send or receive ether

Calling Other Functions Use Case

We need to encode the function name and parameters down to binary level

  • Each function has its function id known as function selector

    • It is first 4 bytes of the function signature

    • Function signature is a string that defines the function name and params

staticcall

  • We use staticcall to call our view or pure functions


Last updated