06. Finance

Token Transfers

The Finance package provides simple token transfer functionality between Gen6 accounts.

Overview

Purpose: Transfer GSX between accounts.

Location: src/packages/finance/

Note: Finance uses only blockchain extrinsics.


Blockchain Extrinsic

Transfer Tokens (Keep Alive)

Transfer tokens while ensuring the sender's account remains above the existential deposit.

Extrinsic: api.tx.balances.transferKeepAlive()

Parameters:

  • recipientAddress: SS58-355 encoded Gen6 address

  • amount: BN (BigNumber) - Amount in smallest unit

Important: transferKeepAlive ensures the sender account doesn't get reaped (deleted) by maintaining the minimum balance required to keep an account alive.

Implementation:

Usage:


Balance Queries

Get Account Balance

Blockchain Query: api.query.system.account()

Parameters:

  • address: SS58-355 encoded address

Implementation:

Response:

Usage:


Existential Deposit

The existential deposit is the minimum balance required to keep an account active on the blockchain.

Why It Matters

  • Accounts below the existential deposit are reaped (deleted)

  • All funds in a reaped account are lost

  • transferKeepAlive prevents this by rejecting transfers that would drop the sender below the existential deposit

Get Existential Deposit

Blockchain Constant: api.consts.balances.existentialDeposit

Implementation:

Usage:


Transaction Status

Track the status of a transfer transaction.

Status Types:

  • Pending: Transaction submitted, waiting for inclusion

  • InBlock: Transaction included in a block (not final)

  • Finalized: Transaction finalized (irreversible)

  • Failed: Transaction failed with error

Implementation:


Address Validation

Validate Gen6 addresses before attempting transfer.

Implementation:

Usage:


Transaction Fees

Every blockchain transaction incurs a fee (gas).

Estimate Transaction Fee

Implementation:

Usage:


Common Errors

"InsufficientBalance"

  • Cause: Not enough tokens in sender account

  • Solution: Check balance before allowing transfer

"InvalidRecipient"

  • Cause: Recipient address is invalid or malformed

  • Solution: Validate address format before submission


Best Practices

  1. Validate addresses - Always check address format before transfer

  2. Show fees - Display estimated transaction fee

  3. Check balance - Validate sufficient balance (amount + fee)

  4. Respect existential deposit - Warn users about minimum balance

  5. Use BN for calculations - Avoid JavaScript number precision issues


Complete Transfer Example

Last updated

Was this helpful?