Tokens
Creating a fungible token
Unlike traditional blockchains where token logic runs over globally ordered blocks, pod allows token contracts to enforce safety (e.g. no overdrafts) even when transactions are confirmed independently and concurrently.
This guide shows how to create and use a simple fungible token using FastTypes.Balance, a type provided by pod-sdk that integrates directly with pod’s validator quorum logic.
To get started, clone podnetwork/pod-sdk github repository and go to examples/tokens directory:
Smart Contract Definition
As in the ERC20 Token Standard, each Token contract instance corresponds to a single fungible token,
defined by its own name, ticker symbol, number of decimals, and fixed total supply.
The contract makes use of the FastTypes library provided by pod-sdk.
The FastTypes.Balances type provides
_balances.decrement(key, owner, value), a method that allows only the owner himself to decrease his balance,_balances.increment(key, owner, value), that allows anyone to increase the balance of an owner
Unlike a plain Solidity mapping, when you call decrement method of a FastTypes.Balance, you’re enforcing that a supermajority of validators agree the account has sufficient funds, up to the previous transaction by this account. That makes balance checks consistent across the network even without full consensus.
The key parameter is a string that allows namespacing for multiple balances by the same owner, but in this example we always use the variable symbol as the key, as there is only a single balance for each address.
Deployment
Transfer token programmatically
This example demonstrates how to transfer tokens programmatically.
Transfer events
Transfer events are emitted on every token transfer.
Clients can request verifiable logs from the RPC full nodes. These proofs can be verified locally if the RPC node is not trusted, or submitted to light clients, ie smart contracts in other blockchains that verify that an event was emitted in pod.