Skip to main content
A deterministic account starts with contract code and initial storage, but no access keys. Its 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 is ft.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’s new 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:
The value 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:
With the example configuration, the output is:
The file now contains the contract’s initial storage, ready for the state-init action. Changing the owner, supply, or metadata changes these bytes and therefore the derived address. If the global publisher changes the contract’s storage layout, the serializer must match that layout.

Derive the address

Run this local computation, which does not submit a transaction:
For the exact storage above, the derived address is:

Create the account

Use the same code reference and storage. Replace alice.testnet in the command with the funded account signing the transaction; the initial token holder is determined separately by ft-state.json.
The CLI derives the receiver address and submits a 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:
The metadata identifies Example Token with symbol EXAMPLE and 6 decimals. Check the total supply and the owner’s balance:
Both return "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 a near-kit example, or Create deterministic accounts for the host functions used by smart contracts.