Prerequisites
Before deploying, ensure you have:Step 1: Compile the Contract
First, compile your contract to WebAssembly:- Rust
- JavaScript
target/near/.The compiled
.wasm file is what gets deployed to the blockchain.Step 2: Create an Account
For Testnet
Create a new testnet account using the faucet:For Mainnet
For mainnet, you’ll need:- A wallet (e.g., MyNearWallet)
- Real NEAR tokens to create the account
- Log in via CLI:
Step 3: Deploy the Contract
Deploy your compiled contract to your account:- Rust
- JavaScript
Network SelectionBy default, NEAR CLI uses testnet. To deploy to mainnet:
Deploy to Existing Account
If you already have an account:Step 4: Initialize the Contract
If your contract has an initialization method, call it after deployment:Initialize During Deployment
You can initialize during deployment:Interacting with Deployed Contract
View Methods
View methods are read-only and free to call:View methods have a default gas limit of 200 TGas.
Call Methods
Call methods modify state and require gas:Call with Deposit
For payable functions, attach NEAR tokens:Specify Gas
Manually specify gas for complex operations:Deployment Costs
Storage Costs
Contracts pay for storage by locking NEAR tokens:- ~1Ⓝ per 100KB of data
- Storage costs are locked, not spent
- Deleting data releases locked tokens
- Small Contract
- Medium Contract
- Large Contract
A simple contract (~50KB):
- Cost: ~0.5Ⓝ
- Example: Hello World, basic counter
Check Contract Size
Best Practices
Test on Testnet First
Test on Testnet First
Always deploy to testnet first:
- Test all functionality
- Have users try it out
- Fix any issues
- Then deploy to mainnet
Use Descriptive Account Names
Use Descriptive Account Names
Choose clear account names:
- ✅
mytoken.near - ✅
marketplace.near - ❌
abc123.near
Document Your Contract
Document Your Contract
After deployment, document:
- Contract methods and parameters
- How to interact with it
- Security considerations
- Admin functions
Plan for Upgrades
Plan for Upgrades
Consider upgrade strategy:
- How will you update the contract?
- Do you need state migration?
- Who can upgrade it?
Monitor Your Contract
Monitor Your Contract
After deployment:
- Monitor contract calls
- Track errors and failures
- Watch for unusual activity
- Use indexers for analytics
Verifying Deployment
Check Contract Code
Verify the contract is deployed:View Contract on Explorer
Visit the NEAR Explorer:- Testnet
- Mainnet
- Contract code hash
- Contract size
- Transaction history
- Contract calls
Common Issues
Error: Account already exists
Error: Account already exists
The account name is taken. Choose a different name:
Error: Insufficient balance
Error: Insufficient balance
Your account needs more NEAR tokens:
- Testnet: Use the faucet again or request from the community
- Mainnet: Add more NEAR to your account
Error: Cannot deserialize contract state
Error: Cannot deserialize contract state
This happens when:
- Contract state structure changed
- Need to migrate state
Contract not initializing
Contract not initializing
If your contract requires initialization:Or use
--initFunction during deployment.Environment Variables
Useful environment variables for deployment:Deployment Checklist
Before deploying to mainnet:Next Steps
Upgrade Contract
Learn how to update deployed contracts
Monitor Activity
Track contract usage and analytics
Build Frontend
Create a web interface for your contract
NEAR CLI
Learn more NEAR CLI commands