Use Cases
- Factories: If you are building a “DAO Factory” or “Token Factory” that deploys new contracts for users, this reduces the deployment cost from ~4 NEAR (storage) to less than 0.1 NEAR.
- Standard Libraries: Publish a standard implementation (like a multisig) that everyone trusts and uses.
1. Publishing Code
Publishing requires a storage deposit proportional to the size of your Wasm file (approx 1 NEAR per 100KB).Updatable Contracts (Default)
By default, published contracts are identified by your account ID. This allows you to update the code later by publishing again. All users who deployed referencing your account will automatically use the latest version you published.{ accountId: "factory.near" } will always get your latest published version.
Immutable Contracts (Trustless)
For trustless protocols or when you want guaranteed immutability, publish the code identified by its SHA-256 hash. It can never be changed.2. Deploying by Reference
To deploy, usedeployFromPublished instead of deployContract. This action is extremely cheap because it uses almost no bandwidth or new storage.
Deploying from Account (Updatable)
This deploys whatever codefactory.near has currently published. If they update the contract later, you’ll automatically get the latest version.
Deploying from Hash (Immutable)
For contracts published withidentifiedBy: "hash", reference them by their SHA-256 hash:
3. Deterministic Account IDs (NEP-616)
NEP-616 enables deploying contracts to deterministic addresses (starting with0s) derived from their initialization state. Perfect for sharded contract designs where you deploy many instances of the same contract.
Deploying with StateInit
"0s" + hex(keccak256(borsh(state_init))[12..32])
Computing Addresses
Why Use This?
- Anyone can deploy: Since addresses are deterministic, anyone can pay to deploy if it doesn’t exist
- Sharded contracts: Deploy many instances with predictable addresses
- Code verification: Verify that another contract is running specific code
See NEP-616 for the full specification.