Documentation

Overview

Package client implements NEO-specific JSON-RPC 2.0 client. This package is currently in alpha and is subject to change.

Client

After creating a client instance with or without a ClientConfig you can interact with the NEO blockchain by its exposed methods.

Some of the methods also allow to pass a verbose bool. This will return a more pretty printed response from the server instead of a raw hex string.

An example:

  endpoint := "http://seed5.bridgeprotocol.io:10332"
  opts := client.Options{}

  c, err := client.New(context.TODO(), endpoint, opts)
  if err != nil {
	  log.Fatal(err)
  }

  if err := c.Ping(); err != nil {
	  log.Fatal(err)
  }

  resp, err := c.GetAccountState("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP")
  if err != nil {
	  log.Fatal(err)
  }
  log.Println(resp.Result.ScriptHash)
  log.Println(resp.Result.Balances)

TODO:

Merge structs so can be used by both server and client.
Add missing methods to client.
Allow client to connect using client cert.
More in-depth examples.

Supported methods

getblock
getaccountstate
getunspents
invokescript
invokefunction
sendrawtransaction
invoke
getrawtransaction

Unsupported methods

validateaddress
getblocksysfee
getcontractstate
getrawmempool
getstorage
submitblock
gettxout
getassetstate
getpeers
getversion
getconnectioncount
getblockhash
getblockcount
getbestblockhash

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

    Client represents the middleman for executing JSON RPC calls to remote NEO RPC nodes.

    func New

    func New(ctx context.Context, endpoint string, opts Options) (*Client, error)

      New returns a new Client ready to use.

      func (*Client) Balancer

      func (c *Client) Balancer() request.BalanceGetter

        Balancer is a getter for balance field.

        func (*Client) CalculateInputs

        func (c *Client) CalculateInputs(address string, asset util.Uint256, cost util.Fixed8) ([]transaction.Input, util.Fixed8, error)

          CalculateInputs creates input transactions for the specified amount of given asset belonging to specified address. This implementation uses GetUnspents JSON-RPC call internally, so make sure your RPC server suppors that.

          func (*Client) Client

          func (c *Client) Client() *http.Client

            Client is a getter for client field.

            func (*Client) GetAccountState

            func (c *Client) GetAccountState(address string) (*result.AccountState, error)

              GetAccountState returns detailed information about a NEO account.

              func (*Client) GetUnspents

              func (c *Client) GetUnspents(address string) (*result.Unspents, error)

                GetUnspents returns UTXOs for the given NEO account.

                func (*Client) Invoke

                func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*response.InvokeResult, error)

                  Invoke returns the results after calling the smart contract scripthash with the given parameters.

                  func (*Client) InvokeFunction

                  func (c *Client) InvokeFunction(script, operation string, params []smartcontract.Parameter) (*response.InvokeResult, error)

                    InvokeFunction returns the results after calling the smart contract scripthash with the given operation and parameters. NOTE: this is test invoke and will not affect the blockchain.

                    func (*Client) InvokeScript

                    func (c *Client) InvokeScript(script string) (*response.InvokeResult, error)

                      InvokeScript returns the result of the given script after running it true the VM. NOTE: This is a test invoke and will not affect the blockchain.

                      func (*Client) Ping

                      func (c *Client) Ping() error

                        Ping attempts to create a connection to the endpoint. and returns an error if there is one.

                        func (*Client) SetBalancer

                        func (c *Client) SetBalancer(b request.BalanceGetter)

                          SetBalancer is a setter for balance field.

                          func (*Client) SetClient

                          func (c *Client) SetClient(cli *http.Client)

                            SetClient is a setter for client field.

                            func (*Client) SetWIF

                            func (c *Client) SetWIF(wif string) error

                              SetWIF decodes given WIF and adds some wallet data to client. Useful for RPC calls that require an open wallet.

                              func (*Client) SignAndPushInvocationTx

                              func (c *Client) SignAndPushInvocationTx(script []byte, wif *keys.WIF, gas util.Fixed8) (util.Uint256, error)

                                SignAndPushInvocationTx signs and pushes given script as an invocation transaction using given wif to sign it and spending the amount of gas specified. It returns a hash of the invocation transaction and an error.

                                func (*Client) TransferAsset

                                func (c *Client) TransferAsset(asset util.Uint256, address string, amount util.Fixed8) (util.Uint256, error)

                                  TransferAsset sends an amount of specific asset to a given address. This call requires open wallet. (`wif` key in client struct.) If response.Result is `true` then transaction was formed correctly and was written in blockchain.

                                  func (*Client) WIF

                                  func (c *Client) WIF() keys.WIF

                                    WIF returns WIF structure associated with the client.

                                    type NeoScanBalance

                                    type NeoScanBalance struct {
                                    	Balance []*Unspent
                                    	Address string
                                    }

                                      NeoScanBalance is a struct of NeoScan response to 'get_balance' request

                                      type NeoScanServer

                                      type NeoScanServer struct {
                                      	URL  string // "protocol://host:port/"
                                      	Path string // path to API endpoint without wallet address
                                      }

                                        NeoScanServer stores NEOSCAN URL and API path.

                                        func (NeoScanServer) CalculateInputs

                                        func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256, cost util.Fixed8) ([]transaction.Input, util.Fixed8, error)

                                          CalculateInputs creates input transactions for the specified amount of given asset belonging to specified address.

                                          func (NeoScanServer) GetBalance

                                          func (s NeoScanServer) GetBalance(address string) ([]*Unspent, error)

                                            GetBalance performs a request to get balance for the address specified.

                                            type Options

                                            type Options struct {
                                            	Cert        string
                                            	Key         string
                                            	CACert      string
                                            	DialTimeout time.Duration
                                            	Client      *http.Client
                                            	// Version is the version of the client that will be send
                                            	// along with the request body. If no version is specified
                                            	// the default version (currently 2.0) will be used.
                                            	Version string
                                            }

                                              Options defines options for the RPC client. All Values are optional. If any duration is not specified a default of 3 seconds will be used.

                                              type Unspent

                                              type Unspent struct {
                                              	Unspent state.UnspentBalances
                                              	Asset   string      // "NEO" / "GAS"
                                              	Amount  util.Fixed8 // total unspent of this asset
                                              }

                                                Unspent stores Unspents per asset