Skip to main content
On NEAR, typically every smart contract account holds its own copy of the Wasm bytecode. This means if you deploy the same Token contract to 1,000 accounts, you are paying for that storage 1,000 times. Global Contracts allow you to publish the Wasm bytecode once to a global registry. You can then deploy instances of that contract by simply referencing its hash.

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.
Users deploying with { 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, use deployFromPublished instead of deployContract. This action is extremely cheap because it uses almost no bandwidth or new storage.

Deploying from Account (Updatable)

This deploys whatever code factory.near has currently published. If they update the contract later, you’ll automatically get the latest version.

Deploying from Hash (Immutable)

For contracts published with identifiedBy: "hash", reference them by their SHA-256 hash:

3. Querying Published Code

You can check what’s in the global registry without deploying anything. getGlobalContract accepts the same reference shape as deployFromPublished and returns the published WASM together with its current SHA-256 hash:
For updatable contracts, the returned hash is the hash of the current version — compare it against a locally computed hash to detect when the publisher has updated the code. To just check existence (for example before deployFromPublished):
If the identifier has no published code, getGlobalContract throws a GlobalContractNotFoundError:
There’s also a matching near.getContractCode("contract.near") for reading the code deployed on a regular account. Note that all of these queries download the full WASM — if you only need a regular contract’s code hash, near.getAccount() is cheaper.

4. Deterministic Account IDs (NEP-616)

NEP-616 enables deploying contracts to deterministic addresses (starting with 0s) derived from their initialization state. Perfect for sharded contract designs where you deploy many instances of the same contract.

Deploying with StateInit

The account ID is derived as: "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.