Near SDK GO is a library designed for smart contract development on the Near Blockchain. This SDK provides the necessary tools for creating, deploying, and testing smart contracts written in Go for the Near Blockchain.
To simplify development on NEAR using Go, you can use the NEAR Go CLI, which streamlines common tasks such as building, deploying, and interacting with smart contracts.
For an optimal development experience, use Go version 1.23.7 and TinyGo version 0.36.0.
For more information about the compatibility between Go and TinyGo, please refer to the following:
Please note that smart contracts run in an isolated environment without access to sockets, files, or other APIs. Therefore, you must test them separately in the Near Blockchain environment before deploying them to production.
TODO:
- Add steps for CLI and manual methods
- Add instructions for running tests, deploying, and calling functions
- Add links on managing keys, account system, etc.
near-go create -p "test1" -m "test1" -t "smart-contract-empty"
near-go build
# Run tests inside the current Go package
near-go test package
# Run tests for the entire project
near-go test project
# Create a testnet account with 10N for future test transactions
# Change accountid.testnet to your preferred account ID
near-go account create -n "testnet" -a "accountid.testnet"
# To deploy your smart contract on the mainnet, import your mainnet account
# Create a mainnet wallet using [Near Wallets](https://wallet.near.org/) providers (e.g., Meteor Wallet)
# Then import it using your seed phrase or private key
near-go account import
# Deploy the smart contract on the testnet or mainnet
# Deploy to testnet
near-go deploy -id "accountid.testnet" -n "testnet"
# Deploy to mainnet
near-go deploy -id "accountid.near" -n "mainnet"
After successful deployment, you can call your smart contract functions and test them:
# Call a method with arguments:
near-go call \
--from fromaccountid.testnet \
--to toaccountid.testnet \
--function WriteData \
--args '{"key": "testKey", "data": "test1"}' \
--gas '100 Tgas' \
--deposit '0 NEAR' \
--network testnet
# Or call a method without arguments:
near-go call \
--from fromaccountid.testnet \
--to toaccountid.testnet \
--function ReadIncommingTxData \
--network testnet
Before deploying to production, review the following resources to ensure your understanding of the NEAR ecosystem:
- NEAR Accounts
- NEAR Access Keys
- NEAR Storage
- Integration Tests on Rust
- Integration Tests on JS
- Build Your Own Indexer on Rust
- Build Your Own Indexer on JS
- Build Your Web3 Client (Frontend)
- Near API JS
For detailed documentation, refer to the doc
folder. It contains all the essential information required for building smart contracts using Go.
If you're a beginner, it's highly recommended to start with the tutorials on the Official NEAR Docs, which guide you through step-by-step lessons. These lessons cover:
For a hands-on experience, go through the Status_Message_Tutorial. This tutorial will teach you how the NEAR-Go CLI works under the hood. You will learn how to:
- Build Go files into WASM smart contracts
- Sign and send transactions
- Deploy code to the blockchain
This will give you a deeper understanding of the full development and deployment process on NEAR using Go.