Tutorial: Creating a Fungible Token

A step-by-step guide to creating, deploying, and managing your own fungible token on the Synergeia network.

Overview

This tutorial will walk you through the process of creating a simple fungible token on the Synergeia network. We will cover the basic implementation of a token smart contract, including functionalities for minting and transferring tokens.

Prerequisites

  • A local Synergeia testnet running. (See the Interactive Testnet Guide)
  • Basic knowledge of Rust and smart contract development.

The Token Smart Contract

Below is a simplified smart contract for a fungible token. This contract will include a total supply, a mapping of balances, and functions to mint new tokens and transfer them between users.

// Note: This is a conceptual example and not production-ready code.

// A simplified representation of our fungible token contract
struct FungibleToken {
    total_supply: u64,
    balances: HashMap,
}

impl FungibleToken {
    // Mint new tokens and assign them to a user
    pub fn mint(&mut self, user: User, amount: u64) {
        self.total_supply += amount;
        *self.balances.entry(user).or_insert(0) += amount;
    }

    // Transfer tokens from one user to another
    pub fn transfer(&mut self, from: User, to: User, amount: u64) {
        // In a real application, you would add checks to ensure the sender has sufficient balance.
        *self.balances.entry(from).or_insert(0) -= amount;
        *self.balances.entry(to).or_insert(0) += amount;
    }
}