Categorygithub.com/edatts/go-massa
modulepackage
0.0.0-20240522203018-212fe8391d04
Repository: https://github.com/edatts/go-massa.git
Documentation: pkg.go.dev

# README

Go-Massa

Go-Massa is an SDK for the Massa blockchain. It allows you to generate and manage wallets, make native MAS transfers, and interact with Smart Contracts on the Massa network.

This SDK is a work in progress and is early in it's development lifecycle. It is not currently funded and is being built as a learning exercise. As such, there are no garuntees that it will reach a stable release and development may be sporadic or cease entirely at any time. Additionally, the public facing api is likely to change significantly as the design evolves.

Current Features

  • Generate Massa accounts.
  • Import existing Massa accounts from secret keys.
  • Securely persist secret keys to disk as per the Massa Standard for wallet files.
  • Automatic public API discovery and reconnection.
  • Initiate native MAS transfers.
  • Read smart contracts.
  • Call smart contracts.

Planned Work / In Progress

  • Add more examples.
  • Improve test coverage.
  • Add structured logger.
  • Top level functions for sending transactions.
  • Add support for seed phrases as per BIP-39.
  • Add support for Heirarchical Deterministic wallets as per SLIP-10.
  • API discovery improvements.
  • API service redundancy and transaction broadcast retries.
  • Utility for serializing smart contract parameters.
  • Read datastore keys and values.
  • Get native balances.
  • Deploy WASM bytecode.
  • Get Operations.
  • Get staking info.
  • ApiClient chain event streams.
  • Custom configuration improvements.
  • Unify all functionality under a "MassaClient".

Future Work

  • Investigate go-massa as a node client.

Usage

Wallet

Generating accounts:

wallet := massa.NewWallet()

if err := wallet.Init(); err != nil {
    log.Fatal(err)
}

// Empty password will result in a user prompt for a password
password := ""
addr, err := wallet.GenerateAccount(password)
if err != nil {
    log.Fatal(err)
}

acc, err := wallet.GetAccount(addr)
if err != nil {
    log.Fatal(err)
}

log.Printf("Account: %+v", acc)

ApiClient

Sending MAS to another account:

var (
    // Don't hardcode secrets in your applications...
    senderSecretKey = "S11JcqZoz6XXbRjN2nrw2CsuKNfcfqwX6Po2EsiwG6jHnhuVLzo"

    // Empty password will prompt for user input.
    senderPassword = ""

    // Amount must be in nanoMAS
    amount uint64 = 1_000_000_000 // 1 MAS

    jsonRpcApi = "https://buildnet.massa.net/api/v2"
    recipientAddr = "AU12oLjNkH8ywGaeqWuSE1CxdWLhG7hsCW8zZgasax1Csn3tW1mni"
)

apiClient := massa.NewApiClient()
if err := apiClient.Init(jsonRpcApi); err != nil {
    log.Fatal(err)
}

wallet := massa.NewWallet()
if err := wallet.Init(); err != nil {
    log.Fatal(err)
}

senderAddr, err := wallet.ImportAccount(senderSecretKey, senderPassword)
if err != nil {
    log.Fatal(err)
}

senderAcc, err := wallet.GetAccount(senderAddr)
if err != nil {
    log.Fatal(err)
}

opId, err := apiClient.SendTransaction(senderAcc, recipientAddr, amount)
if err != nil {
    log.Fatal(err)
}

log.Printf("Operation ID: %s", opId)

# Packages

No description provided by the author
No description provided by the author

# Functions

Generates a Massa Account and saves the corresponding keystore file to the default directory.
Loads the corresponding account and saves the keystore file at the default keystore location (see defaultKeystoreDir()).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Returns a pointer to a new ApiClient, configurable with the provided configuration functions.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Configuration function that sets the maximum number of retries before a getProvider request will return an error.
Configuration function to set the target number of gRPC APIs that should be available at any one time.
COnfiguration function that sets the amount of time to wait after a failed getProvider request before trying again.
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Public API ports.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

ApiClient embeds an api manager that handles automatic api discovery, api reconnects, and getting api endpoints.
No description provided by the author
No description provided by the author
A request that is used to asynchronously get an ApiProvider from the api manager.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Just for keeping track of public methods.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RpcType is an enum that represents one of two types of RPC that is available on each ApiProvider.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author