Documentation ¶
Overview ¶
Package rpcclient implements NEO-specific JSON-RPC 2.0 client. This package is currently in beta 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:
Allow client to connect using client cert. More in-depth examples.
Supported methods
calculatenetworkfee findstates getapplicationlog getbestblockhash getblock getblockcount getblockhash getblockheader getblockheadercount getcommittee getconnectioncount getcontractstate getnativecontracts getnep11balances getnep11properties getnep11transfers getnep17balances getnep17transfers getpeers getrawmempool getrawtransaction getstate getstateheight getstateroot getstorage gettransactionheight getunclaimedgas getnextblockvalidators getversion invokefunction invokescript invokecontractverify sendrawtransaction submitblock submitoracleresponse terminatesession traverseiterator validateaddress
Extensions:
getblocksysfee submitnotaryrequest
Unsupported methods
claimgas dumpprivkey getbalance getmetricblocktimestamp getnewaddress getwalletheight importprivkey listaddress listplugins sendfrom sendmany sendtoaddress
Example ¶
package main import ( "context" "fmt" "os" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/rpcclient" ) func main() { endpoint := "http://seed5.bridgeprotocol.io:10332" opts := rpcclient.Options{} c, err := rpcclient.New(context.TODO(), endpoint, opts) if err != nil { fmt.Println(err) os.Exit(1) } err = c.Init() if err != nil { fmt.Println(err) os.Exit(1) } if err := c.Ping(); err != nil { fmt.Println(err) os.Exit(1) } addr, err := address.StringToUint160("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP") if err != nil { fmt.Println(err) os.Exit(1) } resp, err := c.GetNEP17Balances(addr) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println(resp.Address) fmt.Println(resp.Balances) }
Output:
Index ¶
- type Client
- func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) errordeprecated
- func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
- func (c *Client) CalculateNotaryFee(nKeys uint8) (int64, error)
- func (c *Client) CalculateValidUntilBlock() (uint32, error)deprecated
- func (c *Client) Close()
- func (c *Client) CreateNEP11TransferTx(acc *wallet.Account, tokenHash util.Uint160, gas int64, ...) (*transaction.Transaction, error)
- func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, recipients []TransferTarget, ...) (*transaction.Transaction, error)
- func (c *Client) CreateNEP17TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, ...) (*transaction.Transaction, error)deprecated
- func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64, ...) (*transaction.Transaction, error)deprecated
- func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.Uint160, ...) (result.FindStates, error)
- func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error)
- func (c *Client) GetBestBlockHash() (util.Uint256, error)
- func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error)
- func (c *Client) GetBlockByHashVerbose(hash util.Uint256) (*result.Block, error)
- func (c *Client) GetBlockByIndex(index uint32) (*block.Block, error)
- func (c *Client) GetBlockByIndexVerbose(index uint32) (*result.Block, error)
- func (c *Client) GetBlockCount() (uint32, error)
- func (c *Client) GetBlockHash(index uint32) (util.Uint256, error)
- func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error)
- func (c *Client) GetBlockHeaderCount() (uint32, error)
- func (c *Client) GetBlockHeaderVerbose(hash util.Uint256) (*result.Header, error)
- func (c *Client) GetBlockSysFee(index uint32) (fixedn.Fixed8, error)
- func (c *Client) GetCandidateRegisterPrice() (int64, error)
- func (c *Client) GetCandidates() ([]result.Candidate, error)
- func (c *Client) GetCommittee() (keys.PublicKeys, error)
- func (c *Client) GetConnectionCount() (int, error)
- func (c *Client) GetContractStateByAddressOrName(addressOrName string) (*state.Contract, error)
- func (c *Client) GetContractStateByHash(hash util.Uint160) (*state.Contract, error)
- func (c *Client) GetContractStateByID(id int32) (*state.Contract, error)
- func (c *Client) GetDesignatedByRole(role noderoles.Role, index uint32) (keys.PublicKeys, error)
- func (c *Client) GetExecFeeFactor() (int64, error)
- func (c *Client) GetFeePerByte() (int64, error)
- func (c *Client) GetGasPerBlock() (int64, error)
- func (c *Client) GetMaxNotValidBeforeDelta() (int64, error)
- func (c *Client) GetNEP11Balances(address util.Uint160) (*result.NEP11Balances, error)
- func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error)
- func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error)
- func (c *Client) GetNEP17Balances(address util.Uint160) (*result.NEP17Balances, error)
- func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error)
- func (c *Client) GetNNSPrice(nnsHash util.Uint160) (int64, error)
- func (c *Client) GetNativeContractHash(name string) (util.Uint160, error)
- func (c *Client) GetNativeContracts() ([]state.NativeContract, error)
- func (c *Client) GetNetwork() (netmode.Magic, error)
- func (c *Client) GetNextBlockValidators() ([]result.Validator, error)
- func (c *Client) GetNotaryServiceFeePerKey() (int64, error)
- func (c *Client) GetOraclePrice() (int64, error)
- func (c *Client) GetPeers() (*result.GetPeers, error)
- func (c *Client) GetRawMemPool() ([]util.Uint256, error)
- func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error)
- func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.TransactionOutputRaw, error)
- func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, ...) ([]byte, error)
- func (c *Client) GetStateHeight() (*result.StateHeight, error)
- func (c *Client) GetStateRootByBlockHash(hash util.Uint256) (*state.MPTRoot, error)
- func (c *Client) GetStateRootByHeight(height uint32) (*state.MPTRoot, error)
- func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error)
- func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error)
- func (c *Client) GetStoragePrice() (int64, error)
- func (c *Client) GetTransactionHeight(hash util.Uint256) (uint32, error)
- func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error)
- func (c *Client) GetVersion() (*result.Version, error)
- func (c *Client) Init() error
- func (c *Client) InvokeAndPackIteratorResults(contract util.Uint160, operation string, params []smartcontract.Parameter, ...) (*result.Invoke, error)deprecated
- func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, ...) (*result.Invoke, error)
- func (c *Client) InvokeContractVerifyAtBlock(blockHash util.Uint256, contract util.Uint160, ...) (*result.Invoke, error)
- func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, ...) (*result.Invoke, error)
- func (c *Client) InvokeContractVerifyWithState(stateroot util.Uint256, contract util.Uint160, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunctionAtBlock(blockHash util.Uint256, contract util.Uint160, operation string, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, ...) (*result.Invoke, error)
- func (c *Client) InvokeFunctionWithState(stateroot util.Uint256, contract util.Uint160, operation string, ...) (*result.Invoke, error)
- func (c *Client) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) InvokeScriptAtBlock(blockHash util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) InvokeScriptWithState(stateroot util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error)
- func (c *Client) IsBlocked(hash util.Uint160) (bool, error)
- func (c *Client) MultiTransferNEP17(acc *wallet.Account, gas int64, recipients []TransferTarget, ...) (util.Uint256, error)
- func (c *Client) NEP11BalanceOf(tokenHash, owner util.Uint160) (int64, error)
- func (c *Client) NEP11DBalanceOf(tokenHash, owner util.Uint160, tokenID []byte) (int64, error)
- func (c *Client) NEP11DOwnerOf(tokenHash util.Uint160, tokenID []byte) (uuid.UUID, result.Iterator, error)
- func (c *Client) NEP11DUnpackedOwnerOf(tokenHash util.Uint160, tokenID []byte) ([]util.Uint160, error)
- func (c *Client) NEP11Decimals(tokenHash util.Uint160) (int64, error)
- func (c *Client) NEP11NDOwnerOf(tokenHash util.Uint160, tokenID []byte) (util.Uint160, error)
- func (c *Client) NEP11Properties(tokenHash util.Uint160, tokenID []byte) (*stackitem.Map, error)
- func (c *Client) NEP11Symbol(tokenHash util.Uint160) (string, error)
- func (c *Client) NEP11TokenInfo(tokenHash util.Uint160) (*wallet.Token, error)
- func (c *Client) NEP11Tokens(tokenHash util.Uint160) (uuid.UUID, result.Iterator, error)
- func (c *Client) NEP11TokensOf(tokenHash util.Uint160, owner util.Uint160) (uuid.UUID, result.Iterator, error)
- func (c *Client) NEP11TotalSupply(tokenHash util.Uint160) (int64, error)
- func (c *Client) NEP11UnpackedTokens(tokenHash util.Uint160) ([][]byte, error)
- func (c *Client) NEP11UnpackedTokensOf(tokenHash util.Uint160, owner util.Uint160) ([][]byte, error)
- func (c *Client) NEP17BalanceOf(tokenHash, acc util.Uint160) (int64, error)deprecated
- func (c *Client) NEP17Decimals(tokenHash util.Uint160) (int64, error)deprecated
- func (c *Client) NEP17Symbol(tokenHash util.Uint160) (string, error)deprecated
- func (c *Client) NEP17TokenInfo(tokenHash util.Uint160) (*wallet.Token, error)
- func (c *Client) NEP17TotalSupply(tokenHash util.Uint160) (int64, error)deprecated
- func (c *Client) NNSGetAllRecords(nnsHash util.Uint160, name string) (uuid.UUID, result.Iterator, error)
- func (c *Client) NNSIsAvailable(nnsHash util.Uint160, name string) (bool, error)
- func (c *Client) NNSResolve(nnsHash util.Uint160, name string, typ nns.RecordType) (string, error)
- func (c *Client) NNSUnpackedGetAllRecords(nnsHash util.Uint160, name string) ([]nns.RecordState, error)
- func (c *Client) Ping() error
- func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, error)
- func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee fixedn.Fixed8, ...) (util.Uint256, error)deprecated
- func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fallbackScript []byte, fallbackSysFee int64, ...) (*payload.P2PNotaryRequest, error)
- func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error)deprecated
- func (c *Client) StateRootInHeader() (bool, error)
- func (c *Client) SubmitBlock(b block.Block) (util.Uint256, error)
- func (c *Client) SubmitP2PNotaryRequest(req *payload.P2PNotaryRequest) (util.Uint256, error)
- func (c *Client) SubmitRawOracleResponse(ps []interface{}) error
- func (c *Client) TerminateSession(sessionID uuid.UUID) (bool, error)
- func (c *Client) TransferNEP11(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, tokenID string, ...) (util.Uint256, error)
- func (c *Client) TransferNEP11D(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, amount int64, ...) (util.Uint256, error)
- func (c *Client) TransferNEP17(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, ...) (util.Uint256, error)deprecated
- func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount int) ([]stackitem.Item, error)
- func (c *Client) ValidateAddress(address string) error
- type Notification
- type Options
- type SignerAccount
- type TransferTarget
- type WSClient
- func (c *WSClient) Close()
- func (c *WSClient) GetError() error
- func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error)
- func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error)
- func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error)
- func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error)
- func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, error)
- func (c *WSClient) Unsubscribe(id string) error
- func (c *WSClient) UnsubscribeAll() error
Examples ¶
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. Client is thread-safe and can be used from multiple goroutines.
func New ¶
New returns a new Client ready to use. You should call Init method to initialize network magic the client is operating on.
func (*Client) AddNetworkFee
deprecated
func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs ...*wallet.Account) error
AddNetworkFee adds network fee for each witness script and optional extra network fee to transaction. `accs` is an array signer's accounts.
Deprecated: please use CalculateNetworkFee or actor.Actor. This method will be removed in future versions.
func (*Client) CalculateNetworkFee ¶
func (c *Client) CalculateNetworkFee(tx *transaction.Transaction) (int64, error)
CalculateNetworkFee calculates network fee for the transaction. The transaction may have empty witnesses for contract signers and may have only verification scripts filled for standard sig/multisig signers.
func (*Client) CalculateNotaryFee ¶
CalculateNotaryFee calculates network fee for one dummy Notary witness and NotaryAssisted attribute with NKeys specified. The result should be added to the transaction's net fee for successful verification.
func (*Client) CalculateValidUntilBlock
deprecated
CalculateValidUntilBlock calculates ValidUntilBlock field for tx as current blockchain height + number of validators. Number of validators is the length of blockchain validators list got from GetNextBlockValidators() method. Validators count is being cached and updated every 100 blocks.
Deprecated: please use (*Actor).CalculateValidUntilBlock. This method will be removed in future versions.
func (*Client) Close ¶
func (c *Client) Close()
Close closes unused underlying networks connections.
func (*Client) CreateNEP11TransferTx ¶
func (c *Client) CreateNEP11TransferTx(acc *wallet.Account, tokenHash util.Uint160, gas int64, cosigners []SignerAccount, args ...interface{}) (*transaction.Transaction, error)
CreateNEP11TransferTx creates an invocation transaction for the 'transfer' method of the given contract (token) to move the whole (or the specified amount of) NEP-11 token with the specified token ID to the given account and returns it. The returned transaction is not signed. CreateNEP11TransferTx is also a helper for TransferNEP11 and TransferNEP11D. `args` for TransferNEP11: to util.Uint160, tokenID string, data interface{}; `args` for TransferNEP11D: from, to util.Uint160, amount int64, tokenID string, data interface{}.
func (*Client) CreateNEP17MultiTransferTx ¶
func (c *Client) CreateNEP17MultiTransferTx(acc *wallet.Account, gas int64, recipients []TransferTarget, cosigners []SignerAccount) (*transaction.Transaction, error)
CreateNEP17MultiTransferTx creates an invocation transaction for performing NEP-17 transfers from a single sender to multiple recipients with the given data and cosigners. The transaction sender is included with the CalledByEntry scope by default.
func (*Client) CreateNEP17TransferTx
deprecated
func (c *Client) CreateNEP17TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64, data interface{}, cosigners []SignerAccount) (*transaction.Transaction, error)
CreateNEP17TransferTx creates an invocation transaction for the 'transfer' method of the given contract (token) to move the specified amount of NEP-17 assets (in FixedN format using contract's number of decimals) to the given account and returns it. The returned transaction is not signed.
Deprecated: please use nep17 package, this method will be removed in future versions.
func (*Client) CreateTxFromScript
deprecated
func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, sysFee, netFee int64, cosigners []SignerAccount) (*transaction.Transaction, error)
CreateTxFromScript creates transaction and properly sets cosigners and NetworkFee. If sysFee <= 0, it is determined via result of `invokescript` RPC. You should initialize network magic with Init before calling CreateTxFromScript.
Deprecated: please use actor.Actor API, this method will be removed in future versions.
func (*Client) FindStates ¶
func (c *Client) FindStates(stateroot util.Uint256, historicalContractHash util.Uint160, historicalPrefix []byte, start []byte, maxCount *int) (result.FindStates, error)
FindStates returns historical contract storage item states by the given stateroot, historical contract hash and historical prefix. If `start` path is specified, items starting from `start` path are being returned (excluding item located at the start path). If `maxCount` specified, the maximum number of items to be returned equals to `maxCount`.
func (*Client) GetApplicationLog ¶
func (c *Client) GetApplicationLog(hash util.Uint256, trig *trigger.Type) (*result.ApplicationLog, error)
GetApplicationLog returns a contract log based on the specified txid.
func (*Client) GetBestBlockHash ¶
GetBestBlockHash returns the hash of the tallest block in the blockchain.
func (*Client) GetBlockByHash ¶
GetBlockByHash returns a block by its hash. You should initialize network magic with Init before calling GetBlockByHash.
func (*Client) GetBlockByHashVerbose ¶
GetBlockByHashVerbose returns a block wrapper with additional metadata by its hash. You should initialize network magic with Init before calling GetBlockByHashVerbose.
func (*Client) GetBlockByIndex ¶
GetBlockByIndex returns a block by its height. You should initialize network magic with Init before calling GetBlockByIndex.
func (*Client) GetBlockByIndexVerbose ¶
GetBlockByIndexVerbose returns a block wrapper with additional metadata by its height. You should initialize network magic with Init before calling GetBlockByIndexVerbose. NOTE: to get transaction.ID and transaction.Size, use t.Hash() and io.GetVarSize(t) respectively.
func (*Client) GetBlockCount ¶
GetBlockCount returns the number of blocks in the blockchain.
func (*Client) GetBlockHash ¶
GetBlockHash returns the hash value of the corresponding block based on the specified index.
func (*Client) GetBlockHeader ¶
GetBlockHeader returns the corresponding block header information from a serialized hex string according to the specified script hash. You should initialize network magic with Init before calling GetBlockHeader.
func (*Client) GetBlockHeaderCount ¶
GetBlockHeaderCount returns the number of headers in the main chain.
func (*Client) GetBlockHeaderVerbose ¶
GetBlockHeaderVerbose returns the corresponding block header information from a Json format string according to the specified script hash.
func (*Client) GetBlockSysFee ¶
GetBlockSysFee returns the system fees of the block based on the specified index.
func (*Client) GetCandidateRegisterPrice ¶
GetCandidateRegisterPrice invokes `getRegisterPrice` method on native NEO contract.
func (*Client) GetCandidates ¶
GetCandidates returns the current list of NEO candidate node with voting data and validator status.
func (*Client) GetCommittee ¶
func (c *Client) GetCommittee() (keys.PublicKeys, error)
GetCommittee returns the current public keys of NEO nodes in the committee.
func (*Client) GetConnectionCount ¶
GetConnectionCount returns the current number of the connections for the node.
func (*Client) GetContractStateByAddressOrName ¶
GetContractStateByAddressOrName queries contract information according to the contract address or name.
func (*Client) GetContractStateByHash ¶
GetContractStateByHash queries contract information according to the contract script hash.
func (*Client) GetContractStateByID ¶
GetContractStateByID queries contract information according to the contract ID.
func (*Client) GetDesignatedByRole ¶
GetDesignatedByRole invokes `getDesignatedByRole` method on a native RoleManagement contract.
func (*Client) GetExecFeeFactor ¶
GetExecFeeFactor invokes `getExecFeeFactor` method on a native Policy contract.
func (*Client) GetFeePerByte ¶
GetFeePerByte invokes `getFeePerByte` method on a native Policy contract.
func (*Client) GetGasPerBlock ¶
GetGasPerBlock invokes `getGasPerBlock` method on a native NEO contract.
func (*Client) GetMaxNotValidBeforeDelta ¶
GetMaxNotValidBeforeDelta invokes `getMaxNotValidBeforeDelta` method on a native Notary contract.
func (*Client) GetNEP11Balances ¶
GetNEP11Balances is a wrapper for getnep11balances RPC.
func (*Client) GetNEP11Properties ¶
func (c *Client) GetNEP11Properties(asset util.Uint160, token []byte) (map[string]interface{}, error)
GetNEP11Properties is a wrapper for getnep11properties RPC. We recommend using NEP11Properties method instead of this to receive proper VM types and work with them. This method is provided mostly for the sake of completeness. For well-known attributes like "description", "image", "name" and "tokenURI" it returns strings, while for all others []byte (which can be nil).
func (*Client) GetNEP11Transfers ¶
func (c *Client) GetNEP11Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP11Transfers, error)
GetNEP11Transfers is a wrapper for getnep11transfers RPC. Address parameter is mandatory, while all others are optional. Limit and page parameters are only supported by NeoGo servers and can only be specified with start and stop.
func (*Client) GetNEP17Balances ¶
GetNEP17Balances is a wrapper for getnep17balances RPC.
func (*Client) GetNEP17Transfers ¶
func (c *Client) GetNEP17Transfers(address util.Uint160, start, stop *uint64, limit, page *int) (*result.NEP17Transfers, error)
GetNEP17Transfers is a wrapper for getnep17transfers RPC. Address parameter is mandatory while all the others are optional. Start and stop parameters are supported since neo-go 0.77.0 and limit and page since neo-go 0.78.0. These parameters are positional in the JSON-RPC call. For example, you can't specify the limit without specifying start/stop first.
func (*Client) GetNNSPrice ¶
GetNNSPrice invokes `getPrice` method on a NeoNameService contract with the specified hash.
func (*Client) GetNativeContractHash ¶
GetNativeContractHash returns native contract hash by its name.
func (*Client) GetNativeContracts ¶
func (c *Client) GetNativeContracts() ([]state.NativeContract, error)
GetNativeContracts queries information about native contracts.
func (*Client) GetNetwork ¶
GetNetwork returns the network magic of the RPC node the client connected to.
func (*Client) GetNextBlockValidators ¶
GetNextBlockValidators returns the current NEO consensus nodes information and voting data.
func (*Client) GetNotaryServiceFeePerKey ¶
GetNotaryServiceFeePerKey returns a reward per notary request key for the designated notary nodes. It doesn't cache the result.
func (*Client) GetOraclePrice ¶
GetOraclePrice invokes `getPrice` method on a native Oracle contract.
func (*Client) GetPeers ¶
GetPeers returns a list of the nodes that the node is currently connected to/disconnected from.
func (*Client) GetRawMemPool ¶
GetRawMemPool returns a list of unconfirmed transactions in the memory.
func (*Client) GetRawTransaction ¶
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error)
GetRawTransaction returns a transaction by hash.
func (*Client) GetRawTransactionVerbose ¶
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) GetState ¶
func (c *Client) GetState(stateroot util.Uint256, historicalContractHash util.Uint160, historicalKey []byte) ([]byte, error)
GetState returns historical contract storage item state by the given stateroot, historical contract hash and historical item key.
func (*Client) GetStateHeight ¶
func (c *Client) GetStateHeight() (*result.StateHeight, error)
GetStateHeight returns the current validated and local node state height.
func (*Client) GetStateRootByBlockHash ¶
GetStateRootByBlockHash returns the state root for the block with the specified hash.
func (*Client) GetStateRootByHeight ¶
GetStateRootByHeight returns the state root for the specified height.
func (*Client) GetStorageByHash ¶
GetStorageByHash returns the stored value according to the contract script hash and the stored key.
func (*Client) GetStorageByID ¶
GetStorageByID returns the stored value according to the contract ID and the stored key.
func (*Client) GetStoragePrice ¶
GetStoragePrice invokes `getStoragePrice` method on a native Policy contract.
func (*Client) GetTransactionHeight ¶
GetTransactionHeight returns the block index where the transaction is found.
func (*Client) GetUnclaimedGas ¶
func (c *Client) GetUnclaimedGas(address string) (result.UnclaimedGas, error)
GetUnclaimedGas returns the unclaimed GAS amount for the specified address.
func (*Client) GetVersion ¶
GetVersion returns the version information about the queried node.
func (*Client) Init ¶
Init sets magic of the network client connected to, stateRootInHeader option and native NEO, GAS and Policy contracts scripthashes. This method should be called before any header- or block-related requests in order to deserialize responses properly.
func (*Client) InvokeAndPackIteratorResults
deprecated
func (c *Client) InvokeAndPackIteratorResults(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer, maxIteratorResultItems ...int) (*result.Invoke, error)
InvokeAndPackIteratorResults creates a script containing System.Contract.Call of the specified contract with the specified arguments. It assumes that the specified operation will return iterator. The script traverses the resulting iterator, packs all its values into array and pushes the resulting array on stack. Constructed script is invoked via `invokescript` JSON-RPC API using the provided signers. The result of the script invocation contains single array stackitem on stack if invocation HALTed. InvokeAndPackIteratorResults can be used to interact with JSON-RPC server where iterator sessions are disabled to retrieve iterator values via single `invokescript` JSON-RPC call. It returns maxIteratorResultItems items at max which is set to config.DefaultMaxIteratorResultItems by default.
Deprecated: please use more convenient and powerful invoker.Invoker interface with CallAndExpandIterator method. This method will be removed in future versions.
func (*Client) InvokeContractVerify ¶
func (c *Client) InvokeContractVerify(contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerify returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeContractVerifyAtBlock ¶
func (c *Client) InvokeContractVerifyAtBlock(blockHash util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerifyAtBlock returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type at the blockchain state specified by the block hash. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeContractVerifyAtHeight ¶
func (c *Client) InvokeContractVerifyAtHeight(height uint32, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerifyAtHeight returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type at the blockchain state specified by the blockchain height. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeContractVerifyWithState ¶
func (c *Client) InvokeContractVerifyWithState(stateroot util.Uint256, contract util.Uint160, params []smartcontract.Parameter, signers []transaction.Signer, witnesses ...transaction.Witness) (*result.Invoke, error)
InvokeContractVerifyWithState returns the results after calling `verify` method of the smart contract with the given parameters under verification trigger type at the blockchain state specified by the stateroot hash. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeFunction ¶
func (c *Client) InvokeFunction(contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*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) InvokeFunctionAtBlock ¶
func (c *Client) InvokeFunctionAtBlock(blockHash util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
InvokeFunctionAtBlock returns the results after calling the smart contract with the given operation and parameters at given the blockchain state specified by the block hash. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeFunctionAtHeight ¶
func (c *Client) InvokeFunctionAtHeight(height uint32, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
InvokeFunctionAtHeight returns the results after calling the smart contract with the given operation and parameters at the given blockchain state specified by the blockchain height. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeFunctionWithState ¶
func (c *Client) InvokeFunctionWithState(stateroot util.Uint256, contract util.Uint160, operation string, params []smartcontract.Parameter, signers []transaction.Signer) (*result.Invoke, error)
InvokeFunctionWithState returns the results after calling the smart contract with the given operation and parameters at the given blockchain state defined by the specified stateroot hash. NOTE: this is test invoke and will not affect the blockchain.
func (*Client) InvokeScript ¶
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) InvokeScriptAtBlock ¶
func (c *Client) InvokeScriptAtBlock(blockHash util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error)
InvokeScriptAtBlock returns the result of the given script after running it true the VM using the provided chain state retrieved from the specified block hash. NOTE: This is a test invoke and will not affect the blockchain.
func (*Client) InvokeScriptAtHeight ¶
func (c *Client) InvokeScriptAtHeight(height uint32, script []byte, signers []transaction.Signer) (*result.Invoke, error)
InvokeScriptAtHeight returns the result of the given script after running it true the VM using the provided chain state retrieved from the specified chain height. NOTE: This is a test invoke and will not affect the blockchain.
func (*Client) InvokeScriptWithState ¶
func (c *Client) InvokeScriptWithState(stateroot util.Uint256, script []byte, signers []transaction.Signer) (*result.Invoke, error)
InvokeScriptWithState returns the result of the given script after running it true the VM using the provided chain state retrieved from the specified stateroot hash. NOTE: This is a test invoke and will not affect the blockchain.
func (*Client) MultiTransferNEP17 ¶
func (c *Client) MultiTransferNEP17(acc *wallet.Account, gas int64, recipients []TransferTarget, cosigners []SignerAccount) (util.Uint256, error)
MultiTransferNEP17 is similar to TransferNEP17, buf allows to have multiple recipients.
func (*Client) NEP11BalanceOf ¶
NEP11BalanceOf invokes `balanceOf` NEP-11 method on the specified contract.
func (*Client) NEP11DBalanceOf ¶
NEP11DBalanceOf invokes `balanceOf` divisible NEP-11 method on a specified contract.
func (*Client) NEP11DOwnerOf ¶
func (c *Client) NEP11DOwnerOf(tokenHash util.Uint160, tokenID []byte) (uuid.UUID, result.Iterator, error)
NEP11DOwnerOf returns iterator over the specified NEP-11 divisible token owners. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
func (*Client) NEP11DUnpackedOwnerOf ¶
func (c *Client) NEP11DUnpackedOwnerOf(tokenHash util.Uint160, tokenID []byte) ([]util.Uint160, error)
NEP11DUnpackedOwnerOf returns list of the specified NEP-11 divisible token owners (config.DefaultMaxIteratorResultItems at max). It differs from NEP11DOwnerOf in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
func (*Client) NEP11Decimals ¶
NEP11Decimals invokes `decimals` NEP-11 method on the specified contract.
func (*Client) NEP11NDOwnerOf ¶
NEP11NDOwnerOf invokes `ownerOf` non-divisible NEP-11 method with the specified token ID on the specified contract.
func (*Client) NEP11Properties ¶
NEP11Properties invokes `properties` optional NEP-11 method on the specified contract.
func (*Client) NEP11Symbol ¶
NEP11Symbol invokes `symbol` NEP-11 method on the specified contract.
func (*Client) NEP11TokenInfo ¶
NEP11TokenInfo returns full NEP-11 token info.
func (*Client) NEP11Tokens ¶
NEP11Tokens returns iterator over the tokens minted by the contract. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
func (*Client) NEP11TokensOf ¶
func (c *Client) NEP11TokensOf(tokenHash util.Uint160, owner util.Uint160) (uuid.UUID, result.Iterator, error)
NEP11TokensOf returns iterator over token IDs for the specified owner of the specified NFT token. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
func (*Client) NEP11TotalSupply ¶
NEP11TotalSupply invokes `totalSupply` NEP-11 method on the specified contract.
func (*Client) NEP11UnpackedTokens ¶
NEP11UnpackedTokens returns list of the tokens minted by the contract (config.DefaultMaxIteratorResultItems at max). It differs from NEP11Tokens in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
func (*Client) NEP11UnpackedTokensOf ¶
func (c *Client) NEP11UnpackedTokensOf(tokenHash util.Uint160, owner util.Uint160) ([][]byte, error)
NEP11UnpackedTokensOf returns an array of token IDs for the specified owner of the specified NFT token (config.DefaultMaxIteratorResultItems at max). It differs from NEP11TokensOf in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
func (*Client) NEP17BalanceOf
deprecated
NEP17BalanceOf invokes `balanceOf` NEP-17 method on the specified contract.
Deprecated: please use nep17 package, this method will be removed in future versions. This method is also wrong since tokens can return values overflowing int64.
func (*Client) NEP17TokenInfo ¶
NEP17TokenInfo returns full NEP-17 token info.
func (*Client) NEP17TotalSupply
deprecated
NEP17TotalSupply invokes `totalSupply` NEP-17 method on the specified contract.
Deprecated: please use nep17 package, this method will be removed in future versions. This method is also wrong since tokens can return values overflowing int64.
func (*Client) NNSGetAllRecords ¶
func (c *Client) NNSGetAllRecords(nnsHash util.Uint160, name string) (uuid.UUID, result.Iterator, error)
NNSGetAllRecords returns iterator over records for a given name from NNS service. First return value is the session ID, the second one is Iterator itself, the third one is an error. Use TraverseIterator method to traverse iterator values or TerminateSession to terminate opened iterator session. See TraverseIterator and TerminateSession documentation for more details.
func (*Client) NNSIsAvailable ¶
NNSIsAvailable invokes `isAvailable` method on a NeoNameService contract with the specified hash.
func (*Client) NNSResolve ¶
NNSResolve invokes `resolve` method on a NameService contract with the specified hash.
func (*Client) NNSUnpackedGetAllRecords ¶
func (c *Client) NNSUnpackedGetAllRecords(nnsHash util.Uint160, name string) ([]nns.RecordState, error)
NNSUnpackedGetAllRecords returns a set of records for a given name from NNS service (config.DefaultMaxIteratorResultItems at max). It differs from NNSGetAllRecords in that no iterator session is used to retrieve values from iterator. Instead, unpacking VM script is created and invoked via `invokescript` JSON-RPC call.
func (*Client) Ping ¶
Ping attempts to create a connection to the endpoint and returns an error if there is any.
func (*Client) SendRawTransaction ¶
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (util.Uint256, 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) SignAndPushInvocationTx
deprecated
func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee fixedn.Fixed8, cosigners []SignerAccount) (util.Uint256, error)
SignAndPushInvocationTx signs and pushes the given script as an invocation transaction using the given wif to sign it and the given cosigners to cosign it if possible. It spends the amount of gas specified. It returns a hash of the invocation transaction and an error. If one of the cosigners accounts is neither contract-based nor unlocked, an error is returned.
Deprecated: please use actor.Actor API, this method will be removed in future versions.
func (*Client) SignAndPushP2PNotaryRequest ¶
func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fallbackScript []byte, fallbackSysFee int64, fallbackNetFee int64, fallbackValidFor uint32, acc *wallet.Account) (*payload.P2PNotaryRequest, error)
SignAndPushP2PNotaryRequest creates and pushes a P2PNotary request constructed from the main and fallback transactions using the given wif to sign it. It returns the request and an error. Fallback transaction is constructed from the given script using the amount of gas specified. For successful fallback transaction validation at least 2*transaction.NotaryServiceFeePerKey GAS should be deposited to the Notary contract. Main transaction should be constructed by the user. Several rules should be met for successful main transaction acceptance:
- Native Notary contract should be a signer of the main transaction.
- Notary signer should have None scope.
- Main transaction should have dummy contract witness for Notary signer.
- Main transaction should have NotaryAssisted attribute with NKeys specified.
- NotaryAssisted attribute and dummy Notary witness (as long as the other incomplete witnesses) should be paid for. Use CalculateNotaryWitness to calculate the amount of network fee to pay for the attribute and Notary witness.
- Main transaction either shouldn't have all witnesses attached (in this case none of them can be multisignature), or it only should have a partial multisignature.
Note: client should be initialized before SignAndPushP2PNotaryRequest call.
func (*Client) SignAndPushTx
deprecated
func (c *Client) SignAndPushTx(tx *transaction.Transaction, acc *wallet.Account, cosigners []SignerAccount) (util.Uint256, error)
SignAndPushTx signs the given transaction using the given wif and cosigners and pushes it to the chain. It returns a hash of the transaction and an error. If one of the cosigners accounts is neither contract-based nor unlocked, an error is returned.
Deprecated: please use actor.Actor API, this method will be removed in future versions.
func (*Client) StateRootInHeader ¶
StateRootInHeader returns true if the state root is contained in the block header. You should initialize Client cache with Init() before calling StateRootInHeader.
func (*Client) SubmitBlock ¶
SubmitBlock broadcasts a raw block over the NEO network.
func (*Client) SubmitP2PNotaryRequest ¶
SubmitP2PNotaryRequest submits given P2PNotaryRequest payload to the RPC node.
func (*Client) SubmitRawOracleResponse ¶
SubmitRawOracleResponse submits a raw oracle response to the oracle node. Raw params are used to avoid excessive marshalling.
func (*Client) TerminateSession ¶
TerminateSession tries to terminate the specified session and returns `true` iff the specified session was found on server.
func (*Client) TransferNEP11 ¶
func (c *Client) TransferNEP11(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, tokenID string, data interface{}, gas int64, cosigners []SignerAccount) (util.Uint256, error)
TransferNEP11 creates an invocation transaction that invokes 'transfer' method on the given token to move the whole NEP-11 token with the specified token ID to the given account and sends it to the network returning just a hash of it.
func (*Client) TransferNEP11D ¶
func (c *Client) TransferNEP11D(acc *wallet.Account, to util.Uint160, tokenHash util.Uint160, amount int64, tokenID []byte, data interface{}, gas int64, cosigners []SignerAccount) (util.Uint256, error)
TransferNEP11D creates an invocation transaction that invokes 'transfer' method on the given token to move the specified amount of divisible NEP-11 assets (in FixedN format using contract's number of decimals) to the given account and sends it to the network returning just a hash of it.
func (*Client) TransferNEP17
deprecated
func (c *Client) TransferNEP17(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64, data interface{}, cosigners []SignerAccount) (util.Uint256, error)
TransferNEP17 creates an invocation transaction that invokes 'transfer' method on the given token to move the specified amount of NEP-17 assets (in FixedN format using contract's number of decimals) to the given account with the data specified and sends it to the network returning just a hash of it. Cosigners argument specifies a set of the transaction cosigners (may be nil or may include sender) with a proper scope and the accounts to cosign the transaction. If cosigning is impossible (e.g. due to locked cosigner's account) an error is returned.
Deprecated: please use nep17 package, this method will be removed in future versions.
func (*Client) TraverseIterator ¶
func (c *Client) TraverseIterator(sessionID, iteratorID uuid.UUID, maxItemsCount int) ([]stackitem.Item, error)
TraverseIterator returns a set of iterator values (maxItemsCount at max) for the specified iterator and session. If result contains no elements, then either Iterator has no elements or session was expired and terminated by the server. If maxItemsCount is non-positive, then config.DefaultMaxIteratorResultItems iterator values will be returned using single `traverseiterator` call. Note that iterator session lifetime is restricted by the RPC-server configuration and is being reset each time iterator is accessed. If session won't be accessed within session expiration time, then it will be terminated by the RPC-server automatically.
func (*Client) ValidateAddress ¶
ValidateAddress verifies that the address is a correct NEO address.
type Notification ¶
Notification represents a server-generated notification for client subscriptions. Value can be one of block.Block, state.AppExecResult, state.ContainedNotificationEvent transaction.Transaction or subscriptions.NotaryRequestEvent based on Type.
type Options ¶
type Options struct { // Cert is a client-side certificate, it doesn't work at the moment along // with the other two options below. Cert string Key string CACert string DialTimeout time.Duration RequestTimeout time.Duration // Limit total number of connections per host. No limit by default. MaxConnsPerHost int }
Options defines options for the RPC client. All values are optional. If any duration is not specified, a default of 4 seconds will be used.
type SignerAccount ¶
type SignerAccount struct { Signer transaction.Signer Account *wallet.Account }
SignerAccount represents combination of the transaction.Signer and the corresponding wallet.Account.
type TransferTarget ¶
type TransferTarget struct { Token util.Uint160 Address util.Uint160 Amount int64 Data interface{} }
TransferTarget represents target address, token amount and data for transfer.
type WSClient ¶
type WSClient struct { Client // Notifications is a channel that is used to send events received from // the server. Client's code is supposed to be reading from this channel if // it wants to use subscription mechanism. Failing to do so will cause // WSClient to block even regular requests. This channel is not buffered. // In case of protocol error or upon connection closure, this channel will // be closed, so make sure to handle this. Notifications chan Notification // contains filtered or unexported fields }
WSClient is a websocket-enabled RPC client that can be used with appropriate servers. It's supposed to be faster than Client because it has persistent connection to the server and at the same time it exposes some functionality that is only provided via websockets (like event subscription mechanism). WSClient is thread-safe and can be used from multiple goroutines to perform RPC requests.
func NewWS ¶
NewWS returns a new WSClient ready to use (with established websocket connection). You need to use websocket URL for it like `ws://1.2.3.4/ws`. You should call Init method to initialize the network magic the client is operating on.
func (*WSClient) Close ¶
func (c *WSClient) Close()
Close closes connection to the remote side rendering this client instance unusable.
func (*WSClient) GetError ¶
GetError returns the reason of WS connection closing. It returns nil in case if connection was closed by the use via Close() method calling.
func (*WSClient) SubscribeForExecutionNotifications ¶
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error)
SubscribeForExecutionNotifications adds subscription for notifications generated during transaction execution to this instance of the client. It can be filtered by the contract's hash (that emits notifications), nil value puts no such restrictions.
func (*WSClient) SubscribeForNewBlocks ¶
SubscribeForNewBlocks adds subscription for new block events to this instance of the client. It can be filtered by primary consensus node index, nil value doesn't add any filters.
func (*WSClient) SubscribeForNewTransactions ¶
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error)
SubscribeForNewTransactions adds subscription for new transaction events to this instance of the client. It can be filtered by the sender and/or the signer, nil value is treated as missing filter.
func (*WSClient) SubscribeForNotaryRequests ¶
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error)
SubscribeForNotaryRequests adds subscription for notary request payloads addition or removal events to this instance of client. It can be filtered by request sender's hash, or main tx signer's hash, nil value puts no such restrictions.
func (*WSClient) SubscribeForTransactionExecutions ¶
SubscribeForTransactionExecutions adds subscription for application execution results generated during transaction execution to this instance of the client. It can be filtered by state (HALT/FAULT) to check for successful or failing transactions, nil value means no filtering.
func (*WSClient) Unsubscribe ¶
Unsubscribe removes subscription for the given event stream.
func (*WSClient) UnsubscribeAll ¶
UnsubscribeAll removes all active subscriptions of the current client.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package actor provides a way to change chain state via RPC client.
|
Package actor provides a way to change chain state via RPC client. |
Package nep17 contains RPC wrappers to work with NEP-17 contracts.
|
Package nep17 contains RPC wrappers to work with NEP-17 contracts. |
Package neptoken contains RPC wrapper for common NEP-11 and NEP-17 methods.
|
Package neptoken contains RPC wrapper for common NEP-11 and NEP-17 methods. |
Package unwrap provides a set of proxy methods to process invocation results.
|
Package unwrap provides a set of proxy methods to process invocation results. |