• Discover
  • Partner with us
  • Chapters
  • Blog

Learn everything about Aptos

Course Introduction

Web1 and Web2
The Middleman
Blockchain Comes Into Play
Web3 As a New Iteration for Web
How Smart Contracts Work

What is Aptos?
Features and Advantages of Aptos
Remix Ide Plugin Setups
Move Walkthrough Part-1
Move Walkthrough Part-2

Local Environment Setup
Smart Contract Demonstration Part-1
Smart Contract Demonstration Part-2
Deploying Smart Contract to the Aptos
The Vault Contract Explanation
Submit Your Homework
Bonus: Token Standard in Aptos

Submit Your Final Project

Writing a Smart Contract for Aptos – Introduction to The Vault

Welcome, everyone.

In previous sessions, we explored the fundamentals of the Move language. In this segment, we’ll shift our focus to writing a smart contract designed for the Aptos blockchain.

Overview of the Project

A project structure has already been set up, and in this walkthrough, we’ll build the contract step-by-step. The smart contract we’re developing is called The Vault (VA). Here's how it works:

  • The admin assigns token allocations to user addresses.
  • Users can claim tokens according to their allocations.
  • The admin can only withdraw the portion of tokens that has not been allocated.

For instance, if the Vault holds 100 tokens and 20 tokens are allocated, the admin is only allowed to withdraw the remaining 80 tokens.

Key Components Used

The contract will incorporate the following components:

  • Signer and Coin modules, specifically the Aptos coin.
  • Event handles, which notify the frontend of actions taken within the contract.
  • A dedicated Vault account, giving the Vault a unique on-chain identity.
  • Tables, which are similar to vectors but support key-value pairs for more structured data management.

Error Handling with Codes

To ensure clarity and ease of maintenance, we’ll define error codes for common issues:

  • Unauthorized access – triggered if the transaction sender is not the admin.
  • Insufficient balance – if the contract doesn't hold enough tokens.
  • No allocation – if a user tries to claim tokens without a valid allocation.

These error codes will be stored as constants, making them easier to manage and update across the entire contract.

Events Defined in the Contract

The contract will emit four main events:

  1. AllocationMadeEvent – when the admin allocates tokens to an address.
  2. ClaimEvent – when a user claims their allocated tokens.
  3. TokenDepositEvent – when tokens are deposited into the Vault.
  4. WithdrawEvent – when the admin withdraws unallocated tokens.

Vault Struct and Storage Strategy

The Vault struct is the backbone of the contract. It includes:

  • The admin's address.
  • The Vault's own address.
  • A table of allocations, mapping:
  • Address (key) ➝ Allocation amount (u64) (value).
  • The total allocated token amount.
  • The Vault’s total token balance.
  • Event handles to log on-chain actions.

This design ensures all relevant data is encapsulated within a single struct, making the contract efficient and easy to manage.

Previous
Next

Lesson discussion

Swap insights and ask questions about “Learn everything about Aptos”.

Enroll to participate
Start the course to unlock the discussion. Enrolling helps us keep conversations relevant to learners.
WebsiteDiscoverPartner with UsBlogEvents
Discover
CoursesCircleRustSoliditySolanaWeb3 FundamentalsBlockchain Basics
CompanyAbout UsBrand GuidelineFAQsTerms of UsePrivacy PolicyGDPR NoticeCookies
Don't miss any update!

Disclaimer: The information, programs, and events provided on https://risein.com is strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice, nor do we make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://risein.com disclaims any responsibility for financial decisions made by users based on the information provided here.

© 2026 Rise In, All rights reserved