neo-go: github.com/nspcc-dev/neo-go/pkg/rpc/client Index | Examples | Files

package client

import "github.com/nspcc-dev/neo-go/pkg/rpc/client"

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.

TODO:

Add missing methods to client.
Allow client to connect using client cert.
More in-depth examples.

Supported methods

getaccountstate
getapplicationlog
getassetstate
getbestblockhash
getblock
getblockcount
getblockhash
getblockheader
getblocksysfee
getclaimable
getconnectioncount
getcontractstate
getnep5balances
getnep5transfers
getpeers
getrawmempool
getrawtransaction
getstorage
gettransactionheight
gettxout
getunclaimed
getunspents
getvalidators
getversion
invoke
invokefunction
invokescript
sendrawtransaction
submitblock
validateaddress

Unsupported methods

claimgas
dumpprivkey
getbalance
getmetricblocktimestamp
getnewaddress
getunclaimedgas
getwalletheight
importprivkey
listaddress
listplugins
sendfrom
sendmany
sendtoaddress

Code:

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

c, err := client.New(context.TODO(), endpoint, opts)
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}

if err := c.Ping(); err != nil {
    fmt.Println(err)
    os.Exit(1)
}

resp, err := c.GetAccountState("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
fmt.Println(resp.ScriptHash)
fmt.Println(resp.Balances)

Index

Examples

Package Files

client.go doc.go neoscan.go nep5.go rpc.go

type Client Uses

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

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

func New Uses

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

New returns a new Client ready to use.

func (*Client) Balancer Uses

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

Balancer is a getter for balance field.

func (*Client) CalculateInputs Uses

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 Uses

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

Client is a getter for client field.

func (*Client) GetAccountState Uses

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

GetAccountState returns detailed information about a NEO account.

func (*Client) GetApplicationLog Uses

func (c *Client) GetApplicationLog(hash util.Uint256) (*result.ApplicationLog, error)

GetApplicationLog returns the contract log based on the specified txid.

func (*Client) GetAssetState Uses

func (c *Client) GetAssetState(hash util.Uint256) (*result.AssetState, error)

GetAssetState queries the asset information, based on the specified asset number.

func (*Client) GetBestBlockHash Uses

func (c *Client) GetBestBlockHash() (util.Uint256, error)

GetBestBlockHash returns the hash of the tallest block in the main chain.

func (*Client) GetBlockByHash Uses

func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error)

GetBlockByHash returns a block by its hash.

func (*Client) GetBlockByHashVerbose Uses

func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error)

GetBlockByHashVerbose returns a block wrapper with additional metadata by its hash.

func (*Client) GetBlockByIndex Uses

func (c *Client) GetBlockByIndex(index uint32) (*block.Block, error)

GetBlockByIndex returns a block by its height.

func (*Client) GetBlockByIndexVerbose Uses

func (c *Client) GetBlockByIndexVerbose(index uint32) (*result.Block, error)

GetBlockByIndexVerbose returns a block wrapper with additional metadata by its height. NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.

func (*Client) GetBlockCount Uses

func (c *Client) GetBlockCount() (uint32, error)

GetBlockCount returns the number of blocks in the main chain.

func (*Client) GetBlockHash Uses

func (c *Client) GetBlockHash(index uint32) (util.Uint256, error)

GetBlockHash returns the hash value of the corresponding block, based on the specified index.

func (*Client) GetBlockHeader Uses

func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error)

GetBlockHeader returns the corresponding block header information from serialized hex string according to the specified script hash.

func (*Client) GetBlockHeaderVerbose Uses

func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error)

GetBlockHeaderVerbose returns the corresponding block header information from Json format string according to the specified script hash.

func (*Client) GetBlockSysFee Uses

func (c *Client) GetBlockSysFee(index uint32) (util.Fixed8, error)

GetBlockSysFee returns the system fees of the block, based on the specified index.

func (*Client) GetClaimable Uses

func (c *Client) GetClaimable(address string) (*result.ClaimableInfo, error)

GetClaimable returns tx outputs which can be claimed.

func (*Client) GetConnectionCount Uses

func (c *Client) GetConnectionCount() (int, error)

GetConnectionCount returns the current number of connections for the node.

func (*Client) GetContractState Uses

func (c *Client) GetContractState(hash util.Uint160) (*result.ContractState, error)

GetContractState queries contract information, according to the contract script hash.

func (*Client) GetNEP5Balances Uses

func (c *Client) GetNEP5Balances(address util.Uint160) (*result.NEP5Balances, error)

GetNEP5Balances is a wrapper for getnep5balances RPC.

func (*Client) GetNEP5Transfers Uses

func (c *Client) GetNEP5Transfers(address string) (*result.NEP5Transfers, error)

GetNEP5Transfers is a wrapper for getnep5transfers RPC.

func (*Client) GetPeers Uses

func (c *Client) GetPeers() (*result.GetPeers, error)

GetPeers returns the list of nodes that the node is currently connected/disconnected from.

func (*Client) GetRawMemPool Uses

func (c *Client) GetRawMemPool() ([]util.Uint256, error)

GetRawMemPool returns the list of unconfirmed transactions in memory.

func (*Client) GetRawTransaction Uses

func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error)

GetRawTransaction returns a transaction by hash.

func (*Client) GetRawTransactionVerbose Uses

func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error)

GetRawTransactionVerbose returns a transaction wrapper with additional metadata by transaction's hash. NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.

func (*Client) GetStorage Uses

func (c *Client) GetStorage(hash util.Uint160, key []byte) ([]byte, error)

GetStorage returns the stored value, according to the contract script hash and the stored key.

func (*Client) GetTransactionHeight Uses

func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error)

GetTransactionHeight returns the block index in which the transaction is found.

func (*Client) GetTxOut Uses

func (c *Client) GetTxOut(hash util.Uint256, num int) (*result.TransactionOutput, error)

GetTxOut returns the corresponding unspent transaction output information (returned change), based on the specified hash and index.

func (*Client) GetUnclaimed Uses

func (c *Client) GetUnclaimed(address string) (*result.Unclaimed, error)

GetUnclaimed returns unclaimed GAS amount of the specified address.

func (*Client) GetUnspents Uses

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

GetUnspents returns UTXOs for the given NEO account.

func (*Client) GetValidators Uses

func (c *Client) GetValidators() ([]result.Validator, error)

GetValidators returns the current NEO consensus nodes information and voting status.

func (*Client) GetVersion Uses

func (c *Client) GetVersion() (*result.Version, error)

GetVersion returns the version information about the queried node.

func (*Client) Invoke Uses

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

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

func (*Client) InvokeFunction Uses

func (c *Client) InvokeFunction(script, operation string, params []smartcontract.Parameter) (*result.Invoke, 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 Uses

func (c *Client) InvokeScript(script string) (*result.Invoke, 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) NEP5BalanceOf Uses

func (c *Client) NEP5BalanceOf(tokenHash util.Uint160) (int64, error)

NEP5BalanceOf invokes `balanceOf` NEP5 method on a specified contract.

func (*Client) NEP5Decimals Uses

func (c *Client) NEP5Decimals(tokenHash util.Uint160) (int64, error)

NEP5Decimals invokes `decimals` NEP5 method on a specified contract.

func (*Client) NEP5Name Uses

func (c *Client) NEP5Name(tokenHash util.Uint160) (string, error)

NEP5Name invokes `name` NEP5 method on a specified contract.

func (*Client) NEP5Symbol Uses

func (c *Client) NEP5Symbol(tokenHash util.Uint160) (string, error)

NEP5Symbol invokes `symbol` NEP5 method on a specified contract.

func (*Client) NEP5TokenInfo Uses

func (c *Client) NEP5TokenInfo(tokenHash util.Uint160) (*wallet.Token, error)

NEP5TokenInfo returns full NEP5 token info.

func (*Client) NEP5TotalSupply Uses

func (c *Client) NEP5TotalSupply(tokenHash util.Uint160) (int64, error)

NEP5TotalSupply invokes `totalSupply` NEP5 method on a specified contract.

func (*Client) Ping Uses

func (c *Client) Ping() error

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

func (*Client) SendRawTransaction Uses

func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) error

SendRawTransaction broadcasts a transaction over the NEO network. The given hex string needs to be signed with a keypair. When the result of the response object is true, the TX has successfully been broadcasted to the network.

func (*Client) SetBalancer Uses

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

SetBalancer is a setter for balance field.

func (*Client) SetClient Uses

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

SetClient is a setter for client field.

func (*Client) SetWIF Uses

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 Uses

func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee util.Fixed8, netfee 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) SubmitBlock Uses

func (c *Client) SubmitBlock(b block.Block) error

SubmitBlock broadcasts a raw block over the NEO network.

func (*Client) TransferAsset Uses

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) TransferNEP5 Uses

func (c *Client) TransferNEP5(acc *wallet.Account, to util.Uint160, token *wallet.Token, amount int64, gas util.Fixed8) (util.Uint256, error)

TransferNEP5 creates an invocation transaction that invokes 'transfer' method on a given token to move specified amount of NEP5 assets (in FixedN format using contract's number of decimals) to given account.

func (*Client) ValidateAddress Uses

func (c *Client) ValidateAddress(address string) error

ValidateAddress verifies that the address is a correct NEO address.

func (*Client) WIF Uses

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

WIF returns WIF structure associated with the client.

type NeoScanBalance Uses

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

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

type NeoScanServer Uses

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 Uses

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 Uses

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

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

type Options Uses

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 Uses

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

Unspent stores Unspents per asset

Package client imports 28 packages (graph) and is imported by 3 packages. Updated 2020-04-06. Refresh now. Tools for package owners.