Skip to content

Instantly share code, notes, and snippets.

@jim-toth
Last active October 17, 2023 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jim-toth/7242c59a936dd1ffdbd48f4c7ce529c4 to your computer and use it in GitHub Desktop.
Save jim-toth/7242c59a936dd1ffdbd48f4c7ce529c4 to your computer and use it in GitHub Desktop.
SWS-4 Multi-Token Standard Interface

SWS-4: Multi-Token Standard Interface

Status: Draft

Version: 1.0.0

Author: Jim Toth (jim@artby.city)

Abstract

This document describes the standard interface for SmartWeave Contracts that represent multitple tokenized assets simultaneously.

Motivation

While most SmartWeave Contracts represent tokenized assets with a single, uniform balance structure, there are use cases for combining the balances of more than one token - fungible or non-fungible. For example, a developer may want to track a fungible balance alongside a non-fungible one. Other developers may want to track multiple balances of the same class of fungibility without being fungible between themselves.

Specification

The multi-token standard is identical to the SWS-2: Smartweave Token specification with the addition of an optional parameter tokenId. If tokenId is not provided it should be assumed the "default" token is desired.

Standard Interface

balanceOf

balanceOf(target: Address, tokenId?: string) => { target: Address, balance: number }
  • Returns the current balance of a target address for a given tokenId

transfer

transfer(target: Address, qty: number, tokenId?: string) => void
  • Transfers qty of tokenId tokens to target address
  • SHOULD THROW if the caller does not have enough balance to transfer

name

name(tokenId?: string) => string | undefined
  • Returns the name of the SmartWeave Token for tokenId

ticker

ticker(tokenId?: string) => string | undefined
  • Returns the ticker of the SmartWeave Token for tokenId

decimals

decimals(tokenId?: string) => number
  • Returns the number of decimal places the token amount should display for tokenId
  • MUST return an integer

defaultToken

defaultToken() => string
  • Returns the tokenId of the "default" token
  • MAY be ommitted if the contract state includes a property defaultToken of type string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment