0s address is derived from that initial state, so you can calculate it before creating the account.
This tutorial uses the NEAR CLI on testnet. You need a funded signer account. We will use the global contract already published at ft.globals.primitives.testnet to create a fungible token.
Choose the code and initial storage
You can reference a global contract by its publisher’s account ID or by its code hash. Here, the code reference isft.globals.primitives.testnet.
The initial storage defines a token named Example Token (EXAMPLE), with 6 decimals and a supply of 1,000,000 tokens, all assigned to alice.testnet. The supply is stored as 1000000000000 smallest units.
The FT contract needs three storage entries:
Generate the initial storage
The state-init action writes storage entries directly, so we need to serialize the same state that the FT contract’snew method would create. This includes the token’s metadata, total supply, and initial holder’s balance—not just the arguments you would pass to new.
The published FT source uses Borsh to serialize these values. The CLI expects each storage key and value as a Base64-encoded string in a JSON object.
Save the following as build-ft-state.py. It builds the three entries described above and encodes them for the CLI:
125 is the storage usage per registered account measured by this FT implementation: a one-byte prefix, four-byte string length, 64-byte maximum account ID, 16-byte balance, and 40 bytes of record overhead. The layout matches the published contract’s near-contract-standards 5.15.1 implementation.
Run the script to generate ft-state.json:
Derive the address
Run this local computation, which does not submit a transaction:Create the account
Use the same code reference and storage. Replacealice.testnet in the command with the funded account signing the transaction; the initial token holder is determined separately by ft-state.json.
DeterministicStateInit action. The attached deposit covers any missing storage stake; unused NEAR is refunded.
You do not need a separate CreateAccount, DeployContract, or call to new: the state-init action installs the referenced code and the already-initialized FT storage together.
Check the token
Query the new account’s metadata:EXAMPLE and 6 decimals. Check the total supply and the owner’s balance:
"1000000000000", representing 1,000,000 tokens. If you customized the initial storage, use your derived address and token holder instead.
Create accounts from an application or contract
See NEAR API Libraries for anear-kit example, or Create deterministic accounts for the host functions used by smart contracts.