Git Product home page Git Product logo

gxclient-go's Introduction

gxclient-go

A client to interact with gxchain implemented in go

Supported Versions

go version go1.9.2

Install

You can install this library via go get:

go get github.com/spring820313/gxclient-go

APIs

Constructors

//init GXClient
const (
   	testNetHttp = "https://testnet.gxchain.org"
  	testNetWss = "wss://testnet.gxchain.org" )

client, err := gxc.NewClient(testNetHttp)

Keypair API

//generate key pair locally
func NewKeyPair(seed string) (*KeyPair, error)
//export public key from private key
func (p PrivateKey) PublicKey() *PublicKey
//check if public key is valid
func NewPublicKeyFromString(key string) (*PublicKey, error)
//check if private key is valid
func NewPrivateKeyFromWif(wifPrivateKey string) (*PrivateKey, error)

Chain API

//get current blockchain id
func (api *API) GetChainID() (*string, error)
//get dynamic global properties 
func (api *API) GetDynamicGlobalProperties() (*DynamicGlobalProperties, error)
//get object
func (api *API) GetObjects(assets ...types.ObjectID) ([]json.RawMessage, error)
//get objects
func (api *API) GetObjects(assets ...types.ObjectID) ([]json.RawMessage, error)
// get block by block height
func (api *API) GetBlock(blockNum uint32) (*Block, error)
//send transfer request to entryPoint node
func (client *Client) Transfer(key string, from, to types.ObjectID, amount, fee types.AssetAmount, memo *types.Memo) error
//vote for accounts
func (client *Client) Vote(key string, from string, accounts []string,  proxyAccount string, feeAsset string) error
//broadcast transaction
func (client *Client) broadcast(stx *sign.SignedTransaction) error

Faucet API

//register gxchain account
func (client *Client) Register(account, activeKey, ownerKey, memoKey, faucet string) (interface{}, error)

Account API

// get account info by account name
func (api *API) GetAccountByName(account string) (*types.Account, error)
//get account_ids by public key
func (api *API) GetAccountsByPublicKeys(publicKeys ...string) (*[][]string, error)
//get account balances by account name
func (api *API) GetNamedAccountBalances(account string, assets ...types.ObjectID) ([]*types.AssetAmount, error)

Asset API

//get asset info by symbol
func (api *API) GetAssets(symbols ...string) (*[]Asset, error)

Contract API

// call smart contract method
func (client *Client) CallContract(key string, from string, contractName, method string, parameters interface{}, amount *types.AssetAmount, feeAsset string) error
// create smart contract method
func (client *Client) CreateContract(key string, from string, contractName, code, abi, vmType, vmVersion, feeAsset string) error
// update smart contract method
func (client *Client) UpdateContract(key string, from string, contractName, newOwner, code, abi, feeAsset string) error
//get contract table by contract_name
func (api *API) GetContractTable(account string) (*[]types.Table, error)
//get contract abi by contract_name
func (api *API) GetContractABI(account string) (*types.Abi, error)
//get contract table objects
func (api *API) GetTableObjects(contractName, tableName string, params TableRowsParams) (*interface{}, error) 

Usage

client, err := gxc.NewClient(testNetHttp)
println(err)

//getAccount(account_name) account, err := client.Database.GetAccountByName("spring123")
println(account)

wif := "5K1***" 
priv,_ := types.NewPrivateKeyFromWif(wif)
pubk := priv.PublicKey()
strpub := pubk.String()
println(strpub)

//getAccountByPublicKey(publicKey) accounts, err := client.Database.GetAccountsByPublicKeys("GXC7vr8Wre4UJgJz7H7GmYYGW7NEe6sxdmGhZPDUnHwmKnATrEBu9",
   "GXC7HnJw47kyv7hmHaEwQr1eiuhTHhG7LqySSVdExkmFCHbfgjn2w")
println(accounts)

For more examples, please refer to the examples directory.

Other

  • It's very welcome for developers to translate this project into different programing languages
  • We are looking forward to your pull requests

gxclient-go's People

Contributors

spring820313 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.