A comprehensive Go toolkit for the Massa blockchain ecosystem, providing smart contract development capabilities, client libraries, and wallet functionality.
- Smart Contract SDK (
sc/): Pure Go SDK for developing WebAssembly-compatible smart contracts - Blockchain Client (
client/): Interface to communicate with the Massa blockchain - Wallet Management (
wallet/): Account creation and transaction signing utilities - Complete Examples: End-to-end examples of smart contract development and deployment
- GO go 1.25+
go get github.com/nafsilabs/massa-goA pure Go SDK for developing smart contracts on the Massa blockchain that compile to WebAssembly. This SDK provides a comprehensive set of functions for interacting with the Massa blockchain, similar to the official massa-as-sdk but written in native Go.
Key Features:
- Pure Go Implementation: Write smart contracts in native Go syntax
- WebAssembly Compilation: Compiles to WASM compatible with Massa blockchain
- Complete API Coverage: Implements all major Massa blockchain functions
- Type Safety: Full Go type system with compile-time safety
- Memory Management: Automatic WebAssembly memory handling
- Testing Support: Mock implementations for local development and testing
Quick Start:
package main
import massa "github.com/nafsilabs/massa-go/sc"
func main() {
// Generate an event
massa.GenerateEvent("Hello, Massa!")
// Store data
massa.SetString("greeting", "Hello from Go!")
// Get caller information
caller := massa.Caller()
massa.Printf("Called by: %s", caller.String())
}A comprehensive node client that enables you to communicate with the Massa blockchain. It offers an interface to retrieve data directly from the blockchain, interact with smart contracts, acquire and monitor events, and perform additional actions.
Features:
- Blockchain data retrieval
- Smart contract deployment
- Smart contract interaction
- Event monitoring
- Transaction broadcasting
- Connection management with automatic reconnection
- WebSocket and HTTP API support
- Multi-client connection pooling
Quick Start:
package main
import "github.com/nafsilabs/massa-go/client"
func main() {
// Connect to Massa testnet
massaClient, err := client.NewTestnetClient()
if err != nil {
panic(err)
}
defer massaClient.Close()
// Get node status
status, err := massaClient.GetNodeStatus()
if err != nil {
panic(err)
}
fmt.Printf("Connected to node: %s (slot %d)\n",
status.NodeID, status.CurrentSlot)
// Subscribe to events
eventHandler := func(event *client.Event) {
fmt.Printf("Event: %s\n", event.Data)
}
subscriptionID, err := massaClient.SubscribeToEvents(
&client.EventFilter{}, eventHandler)
if err != nil {
panic(err)
}
// Deploy a smart contract
deployResult, err := massaClient.DeployContract(
&client.ContractDeploymentRequest{
Bytecode: contractBytecode,
MaxGas: 1000000,
Coins: "0",
},
account,
"password",
)
if err != nil {
panic(err)
}
fmt.Printf("Contract deployed: %s\n",
deployResult.ContractAddress)
}Source code inspired by: https://github.com/massalabs/station/tree/main/pkg and https://github.com/massalabs/massa-web3 Smart contract deployment inspired by: https://github.com/massalabs/massa-standards/blob/main/smart-contracts/assembly/contracts/deployer/deployer.ts
Wallet functionality for creating accounts with public and private keys used to sign Massa blockchain transactions.
Features:
- Account generation
- Key management
- Transaction signing
- Address derivation
Some implementation ideas from: https://github.com/massalabs/station/tree/main/pkg
Complete examples demonstrating:
- Smart contract development
- Wallet account creation
- Client usage for deployment
- Smart contract interaction
go mod init your-massa-project
go get github.com/nafsilabs/massa-go// main.go
package main
import massa "github.com/nafsilabs/massa-go/sc"
func main() {
massa.GenerateEvent("Hello, Massa!")
massa.SetString("greeting", "Hello from Go!")
}export GOOS=js
export GOARCH=wasm
go build -ldflags="-s -w" -o contract.wasm main.gopackage main
import (
"context"
"log"
"github.com/nafsilabs/massa-go"
)
func main() {
// Create a Massa gRPC client
client, err := massa.NewMassaClient(&massa.ClientConfig{
Address: "testnet.massa.net:33035",
})
if err != nil {
log.Fatal(err)
}
defer client.Close()
ctx := context.Background()
// Use wallet and client together (see examples/ for full flows)
// ...
_ = ctx
}massa-go/
βββ massa.go # High-level SDK entrypoint
βββ sc/ # Smart Contract SDK
β βββ sc.go # WebAssembly imports
β βββ address.go # Address operations
β βββ storage.go # Storage functions
β βββ context.go # Execution context
β βββ contract.go # Contract interactions
β βββ coins.go # Balance and transfers
β βββ events.go # Events and logging
β βββ crypto.go # Cryptographic functions
β βββ op_datastore.go # Operation datastore
βββ client/ # Blockchain client
βββ wallet/ # Wallet management
βββ examples/
β βββ smart_contract/ # Example smart contract
β βββ main.go # Contract implementation
β βββ build.sh # Build script
β βββ README.md # Example documentation
βββ README.md # This file
The sc/ package provides comprehensive smart contract development capabilities:
- Address Operations: Validation, creation, and utilities
- Storage Management: Persistent key-value storage
- Context Access: Execution environment information
- Contract Interactions: Calling other contracts and bytecode operations
- Coin Operations: Balance queries and transfers
- Event System: Structured event generation and logging
- Cryptography: Hashing, signatures, and utilities
- Operation Datastore: Access to operation-level data
| Module | Description |
|---|---|
Address |
Address validation, creation, and utilities |
Storage |
Persistent key-value storage operations |
Context |
Execution context (caller, timestamp, gas, etc.) |
Contract |
Contract calls, bytecode operations, messaging |
Coins |
Balance queries and coin transfers |
Events |
Event generation and structured logging |
Crypto |
Cryptographic functions (hashing, signatures) |
OpDatastore |
Operation-level data access |
The SDK provides mock implementations for testing:
func TestContract(t *testing.T) {
// The SDK automatically uses mocks when not in WASM runtime
caller := massa.Caller() // Returns mock address
massa.SetString("test", "value")
value := massa.GetString("test")
// Test your contract logic...
}Create an annotated tag and push it to the remote:
# create an annotated tag
git tag -a vX.Y.Z -m "Release vX.Y.Z"
# push the specific tag to origin
git push origin vX.Y.Z
# (optional) push all local tags
git push --tags- Input Validation: Always validate addresses, amounts, and parameters
- Access Control: Implement proper permission checks
- Error Handling: Handle errors gracefully and don't expose internals
- Gas Management: Be mindful of gas costs for operations
- State Consistency: Use atomic operations for multi-step changes
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- massa-as-sdk - Official AssemblyScript SDK
- massa-as-sdk Documentation - SDK documentation
- Massa - Massa blockchain
- Massa Documentation - Official documentation
Built with β€οΈ for the Massa ecosystem