Skip to content

edatts/go-massa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

An SDK for interacting with the Massa network.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages