This example demonstrates how to use NEAR's global contract functionality to deploy and use global smart contracts.
Global contracts allow sharing contract code globally across the NEAR network, reducing deployment costs and enabling efficient code reuse.
- Deploy a global contract using
deploy_global_contract()
- Use an existing global contract by hash with
use_global_contract()
- Use an existing global contract by deployer account with
use_global_contract_by_account_id()
- Integration tests using near-workspaces
cargo near build
cargo test
cargo test --test workspaces
cargo test --test realistic
cargo near create-dev-account
cargo near deploy
- Deploy Global Contract: A contract deploys bytecode as a global contract, making it available network-wide
- Use by Hash: Other contracts can reference the global contract by its code hash
- Use by Account: Contracts can reference a global contract by the account that deployed it
This reduces storage costs and enables code sharing across the ecosystem.
- Multisig Contracts: Deploy once, use for many wallets without paying 3N each time
- Smart Contract Wallets: Efficient user onboarding with chain signatures
- Business Onboarding: Companies can deploy user accounts cost-effectively
- DeFi Templates: Share common contract patterns across protocols
- Current Status: Global contract host functions are implemented in nearcore but will first be available in version 2.7.0
- SDK Status: This near-sdk-rs implementation is ready and waiting for runtime support
- Testing: Integration tests require a custom nearcore build with global contract support
Once nearcore 2.7.0 is released, you'll be able to:
- Deploy global contracts on mainnet and testnet
- Run integration tests with near-workspaces using version "2.7.0" or later
- Use all the functionality demonstrated in this example