Golang client library for MultiChain blockchain
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
address
params
README.md
api_create.go
api_create_test.go
api_createkeypair.go
api_createrawexchange.go
api_createrawsendfrom.go
api_createrawtransaction.go
api_decoderawtransaction.go
api_dumpprivkey.go
api_getaddressbalances.go
api_getaddresses.go
api_getbestblockhash.go
api_getblock.go
api_getinfo.go
api_getnewaddress.go
api_gettxout.go
api_grant.go
api_grantfrom.go
api_importaddress.go
api_importprivkey.go
api_issue.go
api_issuemore.go
api_listaddresses.go
api_listaddresstransactions.go
api_liststreams.go
api_liststreams_test.go
api_listunspent.go
api_preparelockunspent.go
api_preparelockunspentfrom.go
api_revoke.go
api_sendassetfrom.go
api_sendassettoaddress.go
api_sendrawtransaction.go
api_signmessage.go
api_signrawtransaction.go
lockunspent.go
models.go
multichain.go
multichain_test.go

README.md

Golang client library for MultiChain blockchain

This library will allow you to complete a basic set of functions with a MultiChain node.

You should be able to issue, and send assets between addresses.

If you wish to contribute to flesh out the remaining API calls, please make pull requests. My email is alex@cpu.host if you need something urgently.

I actually use a package I forked from this repo for my own http framework, so probably best to just fork this and add more API commands, which I assume most of the users have already done.

Testing

To fully test this package it is neccesary to have a full hot node running at the given parameters.


  chain := flag.String("chain", "", "is the name of the chain")
  host := flag.String("host", "localhost", "is a string for the hostname")
  port := flag.Int("port", 80, "is a number for the host port")
  username := flag.String("username", "multichainrpc", "is a string for the username")
  password := flag.String("password", "12345678", "is a string for the password")

  flag.Parse()

  client := multichain.NewClient(
      *chain,      
      *username,
      *password,
      *port,
  ).ViaNode(
      *host,
      *port
  )
  
  obj, err := client.GetInfo()
  if err != nil {
      panic(err)
  }
  
  fmt.Println(obj)

Deterministic Wallets

Using the address package within this repo, you can create a deterministic keypair with WIF-encoded private-key, and Bitcoin or MultiChain encoded public address.


type KeyPair struct {
    Type string
    Index int
    Public string
    Private string
}

Here is an example of making a multichain HD wallet.

package main

import (
    "fmt"
    "github.com/golangdaddy/multichain-client/address"
    "github.com/golangdaddy/multichain-client/params"
)

const (
    CONST_BCRYPT_DIFF = 10
)

func main() {

    // you need to refer to your params.dat file to get the needed config parameters
    cfg, err := params.Open("./multichain-cold/params.dat")
    if err != nil {
        panic(err)
    }

    // The address package handles the encoding of keys, so it needs to be configued.
    address.Configure(&address.Config{
        PrivateKeyVersion: cfg.String("private-key-version"),
        AddressPubkeyhashVersion: cfg.String("address-pubkeyhash-version"),
        AddressChecksumValue: cfg.String("address-checksum-value"),
    })

    seed := []byte("seed")
    keyChildIndex := 0

    // create a new wallet
    keyPair, err := address.MultiChainWallet(seed, CONST_BCRYPT_DIFF, keyChildIndex)
    if err != nil {
        panic(err)
    }
    
    fmt.Println(keyPair)
}

If you have an existing private key, you can export it as WIF (Wallet Import Format) which can be used with importprivkey API command with MultiChain.


    wif, err := address.MultiChainWIF(privKeyBytes)

...or it's MultiChain address from the public key with the MultiChainAddress function.


    addr, err := address.MultiChainAddress(pubKeyBytes)