How to deploy a smart contract on NEAR using Windows: A step-by-step guide
No Linux expertise required — just WSL, coffee, and patience! ☕
🚨 Troubleshooting common issues
- Permission errors:
- Add sudo to commands (e.g., sudo apt-get update).
-
Node.js/NPM installation fails:
- Reinstall Ubuntu:
wsl --unregister Ubuntu wsl --install --d Ubuntu
- Reinstall Ubuntu:
-
Transaction failures:
- Check gas limits: Use gas: "300000000000000" in functionCall.
- Validate account ID formatting (e.g., alex_work.testnet).
🛠️ Step 1: Set up Windows Subsystem for Linux (WSL)
NEAR’s tooling works best on Linux, but Windows users can bypass this with WSL (a lightweight Linux VM).
Run these commands in PowerShell (Admin):
wsl --set-default-version 2 # Use WSL2 for better performance
wsl --install --d Ubuntu # Install Ubuntu
After installation:
- Launch Ubuntu from the Start Menu.
- Create a UNIX username/password (store it somewhere safe).
💻 Step 2: Install dependencies in Ubuntu
Copy-paste these commands into your Ubuntu terminal:
Update packages, install dev tools, Rust & WASM target, NEAR CLI, and cargo-near
sudo apt-get update && sudo apt upgrade -y
sudo apt-get install gcc make libudev-dev openssl pkg-config unzip -y
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup target add wasm32-unknown-unknown
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
In the end, you should get this:
📦 Step 3: Create & build a smart contract
NEAR’s "hello-near" template is perfect for testing.
Generate a project, compile to WASM
cargo near new hello-near
cd hello-near
cargo near build
Looking for this success message: ✅ Contract successfully built!
🔑 Step 4: Deploy to NEAR testnet
Replace your-account-id.testnet with a unique name (e.g., alex_work.testnet, which I was using ).
Create a testnet account (auto-funded via faucet) and Deploy the contract
near create-account
near deploy
This is a contract code:
// Find all our documentation at https://docs.near.org
use near_sdk::{log, near};
// Define the contract structure
#[near(contract_state)]
pub struct Contract {
greeting: String,
}
// Define the default, which automatically initializes the contract
impl Default for Contract {
fn default() -> Self {
Self {
greeting: "Hello".to_string(),
}
}
}
// Implement the contract structure
#[near]
impl Contract {
// Public method - returns the greeting saved, defaulting to DEFAULT_GREETING
pub fn get_greeting(&self) -> String {
self.greeting.clone()
}
// Public method - accepts a greeting, such as "howdy", and records it
pub fn set_greeting(&mut self, greeting: String) {
log!("Saving greeting: {greeting}");
self.greeting = greeting;
}
}
/*
* The rest of this file holds the inline tests for the code above
* Learn more about Rust tests: https://doc.rust-lang.org/book/ch11-01-writing-tests.html
*/
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_default_greeting() {
let contract = Contract::default();
// this test did not call set_greeting so should return the default "Hello" greeting
assert_eq!(contract.get_greeting(), "Hello");
}
#[test]
fn set_then_get_greeting() {
let mut contract = Contract::default();
contract.set_greeting("howdy".to_string());
assert_eq!(contract.get_greeting(), "howdy");
}
}
My deployment stats (View on NearBlocks):
- Cost: 0.000757 Ⓝ (~$0.0015 USD).
- Time: Less than 1 second.
📝 Step 5: Interact with Your Contract
Set a Greeting (Cost: 0.000168 Ⓝ):
near call
set\_greeting '{"greeting": "Hola NEAR!"}' --accountId Read the Greeting (Free):
near view
get\_greeting Output: "Hola NEAR!"
Total spent: 0.000925 Ⓝ (~$0.002 USD) for deployment + interaction.
🎉 Why NEAR dominates
- Cost: 1000x cheaper than Ethereum.
- Speed: Transactions finalize faster than typing a tweet.
- Simplicity: No MetaMask popups or gas anxiety.
Guides for Further Learning:
Now go build something awesome — and let Ethereum devs wonder how you did it for pennies! 🚀