Aptos Move by Example
  • 🚀Getting Started
  • Set-Up
  • Why is Move Secure
    • Move prover
  • Move vs Solidity
    • Resources
    • Parallel Processing
    • Reentrancy attacks
    • Memory management
    • Smart contract verification
    • Compiled language
  • Basic Concepts
    • Move.toml
    • Primary data-types
    • Strings
    • Comments
    • Functions
    • Function Visibilities
    • Control flow and expressions
    • Loops
    • Error
    • Struct and its Abilities
    • Scripts
    • Operations
  • Intermediate Concepts
    • Local variables
    • Constants
    • Signer
    • Vector
    • Address
    • Uses and Aliases
    • Maps
    • Hash functions
    • References
    • Unit test
    • Generics
    • Type Arguments
    • Type Inference
  • Advanced Concepts
    • Global Storage Structure
    • Global Storage Operations
    • Phantom Type Parameters
    • Timestamps
    • Ownership
    • Move coding conventions
    • View functions
    • Aptos account
    • Aptos Coin
    • Aptos Token(Nft)
    • Object
    • Token V2
  • Applications
    • First App
    • ToDoList
    • Voting System
    • Basic Tokens
    • Storage using Generics
    • Company
    • Collection
    • Football Card
    • Staking Module
    • MultiSender Wallet
    • English Auction
    • Dutch Auction
    • Attendance Sheet
    • Polling Contract
    • Lottery Contract
  • Decentralized Finance
    • Simple Swap Protocol Contract
    • Code of Swapping Protocol
  • Hacks
    • Coming soon
  • Hands on tutorials
    • Indexer tutorials
Powered by GitBook
On this page
Edit on GitHub
  1. Advanced Concepts

View functions

View function is a function that retrieves data from the blockchain without making any changes to it. It is used to read and display data stored on the blockchain.

View functions are important in the Aptos blockchain because they allow external applications to access and display data stored on the blockchain without the need for direct access to the blockchain itself. This can improve the efficiency and security of the blockchain network.

View functions are a recent addition to the Aptos blockchain that allows developers to create a GET API structure to display complex states of smart contracts. In the past, developers had to fetch all the module’s resource data and perform calculations on the client-side, which was time-consuming and inefficient. However, with view functions, developers can now retrieve complex states through a simpler and more streamlined process that saves time and resources. This development has significantly improved the usability of the Aptos blockchain and made it more accessible to developers.

#[view]
public fun get_todos(todo_address: address): vector<String> acquires TodoStore {
    borrow_global<TodoStore>(todo_address).todos
}

With the introduction of view functions, developers can now retrieve complex states from a smart contract in a more streamlined and efficient manner. View functions allow developers to define functions that can return specific data from a smart contract, providing a simple API that can be used by external invokers to retrieve data from the blockchain. This advancement has significantly improved the usability and accessibility of the Aptos blockchain, making it more developer-friendly and easier to use.

Instead of receiving the entire database every time you query it, you can now receive the specific data you need in the desired format using the new view functions.

PreviousMove coding conventionsNextAptos account

Last updated 2 years ago