Overview
The factory exposes two methods for creating tokens:get_requiredquotes the deposit needed for the token’s initial storage.create_tokencreates a sub-account, attaches the global FT implementation, and initializes the token in one atomic batch.
lib.rs
new method:
deploy.rs
Quickstart
- Make sure you have installed Rust.
- Install the NEAR CLI.
- Install cargo-near.
- Clone the example and navigate to its directory:
Build and Deploy the Factory
Compile and deploy the factory to a funded account on testnet:new with these arguments:
ft.globals.primitives.near for mainnet. The factory requires initialization before it can create tokens.
Prepare the Token Arguments
Bothget_required and create_token take an args object containing the owner, total supply, and token metadata. Save the following as token-args.json, replacing the owner with your account:
100000000 represents 100 tokens. The symbol determines the sub-account name: EXAMPLE creates example.<factory-account>. Symbols must contain only ASCII letters and digits, and the resulting account ID must be valid.
Quote the Deposit and Create the Token
Callget_required with the arguments you saved:
create_token with the same arguments:
true on success. If account creation or initialization fails, the callback returns false and refunds the attached deposit to the caller.
You can query the new token’s metadata to verify the result:
storage_deposit method before receiving transfers. Their future storage is not included in the factory’s initial deposit quote.
Factories - Concepts & Limitations
Automatically Creating Accounts
The factory creates direct sub-accounts of itself. For example,factory.testnet can create example.factory.testnet and initialize a token on it.
The created token account has no access keys. Its owner_id identifies the token owner in contract state; it does not give that owner a full access key to the account.
Storage Costs
The deposit quote includes the global reference and the initial state of the published FT implementation:deploy.rs