Skip to content

vlmoon99/near-sdk-go

Repository files navigation

Near SDK GO

Telegram
Pkg Go Dev

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.


🚨 Important Prerequisites 🚨

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.


Quick Start

TODO:

  1. Add steps for CLI and manual methods
  2. Add instructions for running tests, deploying, and calling functions
  3. Add links on managing keys, account system, etc.

1. Create Project

near-go create -p "test1" -m "test1" -t "smart-contract-empty"

2. Build Code

near-go build

3. Test Code

# Run tests inside the current Go package
near-go test package

# Run tests for the entire project
near-go test project

4. Create/Import Account

# 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

5. Deploy Contract

# 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"

6. Call Contract

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

7. Managing in Production

Before deploying to production, review the following resources to ensure your understanding of the NEAR ecosystem:

  1. NEAR Accounts
  2. NEAR Access Keys
  3. NEAR Storage
  4. Integration Tests on Rust
  5. Integration Tests on JS
  6. Build Your Own Indexer on Rust
  7. Build Your Own Indexer on JS
  8. Build Your Web3 Client (Frontend)
  9. Near API JS

Documentation

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:

  1. What is NEAR?
  2. NEAR Accounts
  3. Transactions
  4. What is a Smart Contract?
  5. What are Web3 Apps?

Status Message Tutorial

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.

About

Go library for writing NEAR smart contracts

Resources

License

Stars

Watchers

Forks

Packages

No packages published