Skip to main content

Global Contracts

Global contracts allow smart contracts to be deployed once and reused by any account without incurring high storage costs.


Deploying a Global Contract​

Global contracts can be deployed in 2 ways: either by their hash or by the owner account ID. Contracts deployed by hash are effectively immutable and cannot be updated. When deployed by account id the owner can redeploy the contract updating it for all its users.

Global contracts can be deployed using NEAR CLI. The process is similar to deploying a regular contract but deploy-as-global command should be used instead of deploy.

near contract deploy-as-global use-file <route_to_wasm> as-global-hash <account_id> network-config testnet sign-with-keychain send
info

Note that deploying a global contract incurs high storage costs. Tokens are burned to compensate for storing the contract on-chain, unlike regular contracts where tokens are locked based on contract size.

Using a Global Contract​

A previously deployed global contract can be attached to any NEAR account using NEAR CLI deploy command. Such a contract behaves exactly like a regular contract.

# Using global contract deployed by <global_contract_hash> hash
near contract deploy <account_id> use-global-hash <global_contract_hash> without-init-call network-config testnet
Was this page helpful?