The Scaled UI Amount extension allows token issuers to specify a multiplier to
be used when calculating the UI amount of a user’s token balance. This enables
issuers to create rebasing tokens and to enable things like stock splits. This
extension, like the interest bearing token extension, provides a purely cosmetic
UI amount which means teams need to do some additional work to provide a good
experience. Underlying calculations and transfers all occur using the raw
amounts in the program.
For a user’s live balance you can get updated information on the above amounts
by calling either getTokenAccountBalance or getAccountInfo
If you need to know the UI Amount for an arbitrary amount you can get this
calculation by calling the
amountToUiAmountForMintWithoutSimulation
function or simulating a transaction using amountToUiAmount. The same function
is exported by @solana-program/token-2022 (taking a Kit RPC) and by
@solana/spl-token (taking a legacy web3.js Connection).
Note: amountToUiAmount requires a transaction simulation which means it also
needs a valid fee payer with balance. Because of this, this should not be
the default way to get a balance.
The examples on this page query a devnet token account (2uuv…) and its mint
(BZCd…). The sample output was captured when this page was written, so the
amounts, multiplier, and slots you get will differ.
getTokenAccountBalance
Returns the token account balance and the mint info
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
Because Issuers can update the multiplier at any given time you can consider
occasionally polling in order to keep the account balance updated. Issuers are
unlikely to update this multiplier more than once per day. If a multiplier is
set for a future date, you can automatically poll at this update time
Token Amounts in Transactions (transfers / swaps etc)
Users should enter amounts to be interpreted as the scaled “UIAmount”. The app
that has to process this should convert to the raw token amount for the
transaction.
If there are rounding issues, round down and prefer leaving a tiny amount of
dust rather than risk the transaction failing
To do this conversion you can use the
uiAmountToAmountForMintWithoutSimulation
function (exported by @solana-program/token-2022 for Kit and by
@solana/spl-token) or simulating a transaction using amountToUiAmount. On
web3.js v3 you can also read the multiplier off the decoded mint, pick the
active one using the cluster’s Clock sysvar timestamp, and convert locally
with uiAmountToAmountForScaledUiAmountMintWithoutSimulation, as below.
The code on this page imports Clock sysvar helpers from @solana/sysvars,
which @solana/kit does not re-export. Install it explicitly:
npm i @solana/sysvars.
import { address, createSolanaRpc } from "@solana/kit";import { uiAmountToAmountForMintWithoutSimulation } from "@solana-program/token-2022";const rpc = createSolanaRpc("https://api.devnet.solana.com");const mint = address("BZCd6HfTbb5ZYJ8hQsm8282tG4QzLyeqFR6tdgQA9EAG");const uiAmount = "20.2";const rawAmount = await uiAmountToAmountForMintWithoutSimulation( rpc, mint, uiAmount);console.log("Raw Amount:", rawAmount);/* Raw Amount: 10100000n */
import { Connection, PublicKey, SYSVAR_CLOCK_PUBKEY, clusterApiUrl} from "@solana/web3.js";import { unwrapOption } from "@solana/kit";import { getSysvarClockDecoder } from "@solana/sysvars";import { getMintDecoder, uiAmountToAmountForScaledUiAmountMintWithoutSimulation} from "@solana-program/token-2022";const connection = new Connection(clusterApiUrl("devnet"), "confirmed");const mint = new PublicKey("BZCd6HfTbb5ZYJ8hQsm8282tG4QzLyeqFR6tdgQA9EAG");const uiAmount = "20.2";const [mintAccountInfo, clockAccountInfo] = await connection.getMultipleAccountsInfo([mint, SYSVAR_CLOCK_PUBKEY]);const mintAccount = getMintDecoder().decode(mintAccountInfo!.data);const { unixTimestamp } = getSysvarClockDecoder().decode( clockAccountInfo!.data);const scaledUiAmountConfig = (unwrapOption(mintAccount.extensions) ?? []).find( (extension) => extension.__kind === "ScaledUiAmountConfig");if (!scaledUiAmountConfig) { throw new Error("ScaledUiAmountConfig not found");}const multiplier = unixTimestamp >= scaledUiAmountConfig.newMultiplierEffectiveTimestamp ? scaledUiAmountConfig.newMultiplier : scaledUiAmountConfig.multiplier;const rawAmount = uiAmountToAmountForScaledUiAmountMintWithoutSimulation( uiAmount, mintAccount.decimals, multiplier);console.log("Raw Amount:", rawAmount);/* Raw Amount: 10100000n */
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
import { uiAmountToAmountForMintWithoutSimulation } from "@solana/spl-token";import { Connection, PublicKey, clusterApiUrl } from "@solana/web3.js";const connection = new Connection(clusterApiUrl("devnet"), "confirmed");const mint = new PublicKey("BZCd6HfTbb5ZYJ8hQsm8282tG4QzLyeqFR6tdgQA9EAG");const uiAmount = "20.2";const rawAmount = await uiAmountToAmountForMintWithoutSimulation( connection as unknown as Connection, mint, uiAmount);console.log("Raw Amount:", rawAmount);/* Raw Amount: 10100000n */
Apps should use the total raw amount when a user requests to do an action with
“max” or “all” of their balance. This ensures that there is no dust left over.
Optional: You can consider automatically closing an account when “max” is
used to refund the user of their storage deposit
Security: Keep program logic on raw amountsOnchain programs should compute balances, shares, and prices from the raw
amount. The multiplier changes when the issuer updates it, so a value
calculated from a UI amount can be wrong by the time the transaction lands.
Convert to UI amounts only for display, and round down when converting user
input to raw amounts.
The current multiplier can be read from the token mint at any time by calling
getAccountInfo. Additionally, if a future multiplier is set, this
information is also available from the token mint. We recommend not showing
this multiplier as it can confuse the UX.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
import { type AccountInfo, Connection, type ParsedAccountData, PublicKey, SYSVAR_CLOCK_PUBKEY, clusterApiUrl} from "@solana/web3.js";const connection = new Connection(clusterApiUrl("devnet"), "confirmed");const mint = new PublicKey("BZCd6HfTbb5ZYJ8hQsm8282tG4QzLyeqFR6tdgQA9EAG");const accountInfo = await connection.getParsedAccountInfo(mint);const clockAccountInfo = await connection.getParsedAccountInfo(SYSVAR_CLOCK_PUBKEY);const { unixTimestamp } = (clockAccountInfo.value?.data as ParsedAccountData) .parsed.info as { unixTimestamp: number };const mintData = accountInfo?.value as AccountInfo<ParsedAccountData>;const mintDataParsed = mintData?.data.parsed as Readonly<{ info?: { extensions: { extension: string; state: object; }[]; }; type: string;}>;const scaledUiAmountConfig = mintDataParsed.info?.extensions?.find( (extension) => extension.extension === "scaledUiAmountConfig") as Readonly<{ state: { newMultiplierEffectiveTimestamp: number; newMultiplier: number; multiplier: number; };}>;const currentMultiplier = scaledUiAmountConfig?.state && unixTimestamp >= scaledUiAmountConfig.state.newMultiplierEffectiveTimestamp ? scaledUiAmountConfig.state.newMultiplier : scaledUiAmountConfig.state.multiplier;console.log("Scaled UI Amount Config:", scaledUiAmountConfig);console.log("Current Multiplier:", currentMultiplier);/*Scaled UI Amount Config: { extension: 'scaledUiAmountConfig', state: { authority: 'G7ARQSUCwNrfvTDUCZvM5xdiRdBJiN3qVw2PryD8Wnib', multiplier: '2', newMultiplier: '2', newMultiplierEffectiveTimestamp: 1743000000 }}Current Multiplier: 2*/
Services who provide historical data should store and surface both the
scaled and non-scaled prices for the scaled UI amount extension.
We expect scaled amounts to be used most frequently as this aligns with how
the traditional finance world treats charts related to tokens with stock
splits.
Multiplier updates may include a timestamp that’s in the past. We recommend
using the block timestamp for historical data.
Note that the active multiplier may be the “multiplier” or the “newMultiplier”
depending on the current timestamp and when the new multiplier is set to be
active.
If you would like to show the balance transferred in the past you need access
to the multiplier at that given slot. You can also save the UiAmount for
transfers as you process transactions to avoid doing this calculation in the
future.
By default wallets and applications that do not understand the scaled UI
amount extension will show the correct total price of an activity by
multiplying the non-scaled price * raw amount.
They would, however, display the non-scaled price causing some user confusion.
We hope this encourages teams to update their dApps to be compatible with
tokens that use the scaled UI amount extension and are happy to provide
support during this process.
All user actions should be entered in UiAmount when UiAmount is enabled throughout the app. If UiAmount is not visible in the app, they should use raw amounts until the app is updated.
Extend API functionality to include multiplier changes over time as well as the scaled price feed.
P0
Total Supply With Scaled Adjustment
When displaying total supply and total market cap, take the scaled balances into account
P0
Historical Price Tracking
Provide a historical chart of prices using the scaled price over time.
P1
Historical Multiplier Tracking
Provide historical markers of multiplier updates for Scaled UI Amount tokens. Note that multiplier updates may include a timestamp that’s in the past. We recommend using the block timestamp instead of the timestamp indicated in the multiplier update for historical data.
P2
Educational Content or Explanations
Include brief descriptions or tooltips explaining how scaled tokens work.
Provide price feeds for both scaled and non-scaled prices.
P0
Historical Multiplier Data
Offer APIs with historical multiplier changes. Note that multiplier updates may include a timestamp that’s in the past. We recommend using the block timestamp instead of the timestamp indicated in the multiplier update for historical data.
P0
Historical Price Data
Offer APIs with historical prices based on both scaled and non-scaled amounts.