Documentation ¶
Overview ¶
Package near allows to interact with the NEAR platform via RPC calls.
Index ¶
- Variables
- func GetTransactionLastResult(txResult map[string]interface{}) (interface{}, error)
- type AccessKey
- type AccessKeyPermission
- type Account
- func (a *Account) AccountID() string
- func (a *Account) AddKeys(publicKeys ...utils.PublicKey) (map[string]interface{}, error)
- func (a *Account) CreateAccount(newAccountID string, publicKey utils.PublicKey, amount big.Int) (map[string]interface{}, error)
- func (a *Account) DeleteAccount(beneficiaryID string) (map[string]interface{}, error)
- func (a *Account) DeleteKeys(publicKeys ...utils.PublicKey) (map[string]interface{}, error)
- func (a *Account) FunctionCall(contractID, methodName string, args []byte, gas uint64, amount big.Int) (map[string]interface{}, error)
- func (a *Account) FunctionCallAsync(contractID, methodName string, args []byte, gas uint64, amount big.Int) (string, error)
- func (a *Account) FunctionCallAsyncWithMultiActionAndKey(contractID string, methodName string, publicKey string, argsSlice [][]byte, ...) (string, error)
- func (a *Account) FunctionCallWithMultiActionAndKey(contractID string, methodName string, publicKey string, argsSlice [][]byte, ...) (map[string]interface{}, error)
- func (a *Account) FunctionCallWithMultiActionAndKeyAndNonce(contractID string, methodName string, publicKey string, argsSlice [][]byte, ...) (map[string]interface{}, error)
- func (a *Account) GetVerifiedAccessKeys() []string
- func (a *Account) SendMoney(receiverID string, amount big.Int) (map[string]interface{}, error)
- func (a *Account) SignAndSendTransaction(receiverID string, actions []Action) (map[string]interface{}, error)
- func (a *Account) SignAndSendTransactionAsync(receiverID string, actions []Action) (string, error)
- func (a *Account) SignAndSendTransactionAsyncWithKey(receiverID string, publicKey string, actions []Action) (string, error)
- func (a *Account) SignAndSendTransactionWithKey(receiverID string, publicKey string, actions []Action) (map[string]interface{}, error)
- func (a *Account) SignAndSendTransactionWithKeyAndNonce(receiverID string, publicKey string, nonce uint64, actions []Action) (map[string]interface{}, error)
- func (a *Account) ViewAccessKey(publicKey string) (map[string]interface{}, error)
- func (a *Account) ViewFunction(accountId, methodName string, argsBuf []byte, options *int64) (interface{}, error)
- func (a *Account) ViewNonce(publicKey string) (uint64, error)
- type Action
- type AddKey
- type Config
- type Connection
- func (c *Connection) Block() (map[string]interface{}, error)
- func (c *Connection) Call(method string, params ...interface{}) (interface{}, error)
- func (c *Connection) GetAccountState(accountID string) (map[string]interface{}, error)
- func (c *Connection) GetBlockByHash(blockHash string) (map[string]interface{}, error)
- func (c *Connection) GetBlockByID(blockID uint64) (map[string]interface{}, error)
- func (c *Connection) GetChunkByID(chunkID string) (map[string]interface{}, error)
- func (c *Connection) GetContractCode(accountID string) (map[string]interface{}, error)
- func (c *Connection) GetNodeStatus() (map[string]interface{}, error)
- func (c *Connection) GetTransactionDetails(txHash, senderAccountId string) (map[string]interface{}, error)
- func (c *Connection) GetTransactionDetailsWithReceipts(txHash, senderAccountId string) (map[string]interface{}, error)
- func (c *Connection) GetTransactionDetailsWithWait(txHash, senderAccountId string, waitUntil TxExecutionStatus) (map[string]interface{}, error)
- func (c *Connection) SendTransaction(signedTransaction []byte) (map[string]interface{}, error)
- func (c *Connection) SendTransactionAsync(signedTransaction []byte) (string, error)
- func (c *Connection) ViewAccessKey(accountID, publicKey string) (map[string]interface{}, error)
- func (c *Connection) ViewAccessKeyList(accountID string) (map[string]interface{}, error)
- type DeleteAccount
- type DeleteKey
- type DeployContract
- type FunctionCall
- type FunctionCallPermission
- type Signature
- type SignedTransaction
- type Stake
- type Transaction
- type Transfer
- type TxExecutionStatus
Constants ¶
This section is empty.
Variables ¶
var ErrNotObject = errors.New("near: JSON-RPC result is not an object")
ErrNotObject is returned if a result is not an object, but should be.
var ErrNotString = errors.New("near: JSON-RPC result is not a string")
ErrNotString is returned if a result is not a string, but should be.
Functions ¶
func GetTransactionLastResult ¶
GetTransactionLastResult decodes the last transaction result from a JSON map and tries to deterimine if we have an error condition.
Types ¶
type AccessKey ¶
type AccessKey struct { Nonce uint64 Permission AccessKeyPermission }
AccessKey encodes a NEAR access key.
type AccessKeyPermission ¶
type AccessKeyPermission struct { Enum borsh.Enum `borsh_enum:"true"` // treat struct as complex enum when serializing/deserializing FunctionCall FunctionCallPermission FullAccess borsh.Enum }
AccessKeyPermission encodes a NEAR access key permission.
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
Account defines functions to work with a NEAR account. Keeps a connection to NEAR JSON-RPC, the account's access keys, and maintains a local cache of nonces per account's access key.
func LoadAccount ¶
func LoadAccount(c *Connection, cfg *Config, accountID string) (*Account, error)
LoadAccount initializes an Account object by loading the account credentials from disk.
func LoadAccountWithKeyPair ¶
func LoadAccountWithKeyPair(c *Connection, keyPair *keystore.Ed25519KeyPair) *Account
LoadAccountWithKeyPair initializes an Account object given its access key pair.
func LoadAccountWithPrivateKey ¶
func LoadAccountWithPrivateKey(c *Connection, accountID string, privateKey ed25519.PrivateKey) *Account
LoadAccountWithPrivateKey initializes an Account object given its accountID and a private key.
func (*Account) CreateAccount ¶
func (a *Account) CreateAccount( newAccountID string, publicKey utils.PublicKey, amount big.Int, ) (map[string]interface{}, error)
CreateAccount creates the newAccountID with the given publicKey and amount.
func (*Account) DeleteAccount ¶
DeleteAccount deletes the account and sends the remaining Ⓝ balance to the account beneficiaryID.
func (*Account) DeleteKeys ¶
DeleteKeys deletes the given publicKeys from the account.
func (*Account) FunctionCall ¶
func (a *Account) FunctionCall( contractID, methodName string, args []byte, gas uint64, amount big.Int, ) (map[string]interface{}, error)
FunctionCall performs a NEAR function call.
func (*Account) FunctionCallAsync ¶
func (a *Account) FunctionCallAsync( contractID, methodName string, args []byte, gas uint64, amount big.Int, ) (string, error)
FunctionCallAsync performs an async NEAR function call.
func (*Account) FunctionCallAsyncWithMultiActionAndKey ¶
func (a *Account) FunctionCallAsyncWithMultiActionAndKey( contractID string, methodName string, publicKey string, argsSlice [][]byte, gas uint64, amount big.Int, ) (string, error)
FunctionCallAsyncWithMultiActionAndKey performs an async NEAR function call.
func (*Account) FunctionCallWithMultiActionAndKey ¶
func (a *Account) FunctionCallWithMultiActionAndKey( contractID string, methodName string, publicKey string, argsSlice [][]byte, gas uint64, amount big.Int, ) (map[string]interface{}, error)
FunctionCallWithMultiActionAndKey performs a NEAR function call for multiple actions with specific access key.
func (*Account) FunctionCallWithMultiActionAndKeyAndNonce ¶
func (a *Account) FunctionCallWithMultiActionAndKeyAndNonce( contractID string, methodName string, publicKey string, argsSlice [][]byte, gas uint64, nonce uint64, amount big.Int, ) (map[string]interface{}, error)
FunctionCallWithMultiActionAndKeyAndNonce performs a NEAR function call for multiple actions with specific access key and nonce.
func (*Account) GetVerifiedAccessKeys ¶
GetVerifiedAccessKeys verifies and returns the public keys of the access keys
func (*Account) SignAndSendTransaction ¶
func (a *Account) SignAndSendTransaction( receiverID string, actions []Action, ) (map[string]interface{}, error)
SignAndSendTransaction signs the given actions and sends them as a transaction to receiverID.
func (*Account) SignAndSendTransactionAsync ¶
func (a *Account) SignAndSendTransactionAsync( receiverID string, actions []Action, ) (string, error)
SignAndSendTransactionAsync signs the given actions and sends it immediately
func (*Account) SignAndSendTransactionAsyncWithKey ¶
func (a *Account) SignAndSendTransactionAsyncWithKey( receiverID string, publicKey string, actions []Action, ) (string, error)
SignAndSendTransactionAsyncWithKey signs the given actions and sends it immediately
func (*Account) SignAndSendTransactionWithKey ¶
func (a *Account) SignAndSendTransactionWithKey( receiverID string, publicKey string, actions []Action, ) (map[string]interface{}, error)
SignAndSendTransactionWithKey signs the given actions and sends them as a transaction to receiverID.
func (*Account) SignAndSendTransactionWithKeyAndNonce ¶
func (a *Account) SignAndSendTransactionWithKeyAndNonce( receiverID string, publicKey string, nonce uint64, actions []Action, ) (map[string]interface{}, error)
SignAndSendTransactionWithKeyAndNonce signs the given actions and sends them as a transaction to receiverID.
func (*Account) ViewAccessKey ¶
type Action ¶
type Action struct { Enum borsh.Enum `borsh_enum:"true"` // treat struct as complex enum when serializing/deserializing CreateAccount borsh.Enum DeployContract DeployContract FunctionCall FunctionCall Transfer Transfer Stake Stake AddKey AddKey DeleteKey DeleteKey DeleteAccount DeleteAccount }
Action simulates an enum for Borsh encoding.
type Config ¶
type Config struct { NetworkID string NodeURL string KeyPath string FunctionKeyPrefixPattern string }
A Config for the NEAR network.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection allows to do JSON-RPC to a NEAR endpoint.
func NewConnection ¶
func NewConnection(nodeURL string) *Connection
NewConnection returns a new connection for JSON-RPC calls to the NEAR endpoint with the given nodeURL.
func NewConnectionWithTimeout ¶
func NewConnectionWithTimeout(nodeURL string, timeout time.Duration) *Connection
NewConnectionWithTimeout returns a new connection for JSON-RPC calls to the NEAR endpoint with the given nodeURL with the given timeout.
func (*Connection) Block ¶
func (c *Connection) Block() (map[string]interface{}, error)
Block queries network and returns latest block.
For details see https://docs.near.org/docs/interaction/rpc#block
func (*Connection) Call ¶
func (c *Connection) Call(method string, params ...interface{}) (interface{}, error)
Call performs a generic call of the given NEAR JSON-RPC method with params. It handles all possible error cases and returns the result (which cannot be nil).
func (*Connection) GetAccountState ¶
func (c *Connection) GetAccountState(accountID string) (map[string]interface{}, error)
GetAccountState returns basic account information for given accountID.
For details see https://docs.near.org/docs/api/rpc/contracts#view-account
func (*Connection) GetBlockByHash ¶
func (c *Connection) GetBlockByHash(blockHash string) (map[string]interface{}, error)
Block with given blockHash queries network and returns block with given hash.
For details see https://docs.near.org/api/rpc/block-chunk#block-details
func (*Connection) GetBlockByID ¶
func (c *Connection) GetBlockByID(blockID uint64) (map[string]interface{}, error)
Block with given blockId queries network and returns block with given ID.
For details see https://docs.near.org/api/rpc/block-chunk#block-details
func (*Connection) GetChunkByID ¶ added in v1.0.1
func (c *Connection) GetChunkByID(chunkID string) (map[string]interface{}, error)
func (*Connection) GetContractCode ¶
func (c *Connection) GetContractCode(accountID string) (map[string]interface{}, error)
GetContractCode returns the contract code (Wasm binary) deployed to the account.
For details see https://docs.near.org/docs/api/rpc/contracts#view-contract-code
func (*Connection) GetNodeStatus ¶
func (c *Connection) GetNodeStatus() (map[string]interface{}, error)
GetNodeStatus returns general status of a given node.
For details see https://docs.near.org/docs/api/rpc/network#node-status
func (*Connection) GetTransactionDetails ¶
func (c *Connection) GetTransactionDetails(txHash, senderAccountId string) (map[string]interface{}, error)
GetTransactionDetails returns information about a single transaction.
For details see https://docs.near.org/api/rpc/transactions#transaction-status
func (*Connection) GetTransactionDetailsWithReceipts ¶
func (c *Connection) GetTransactionDetailsWithReceipts(txHash, senderAccountId string) (map[string]interface{}, error)
GetTransactionDetailsWithReceipts returns information about a single transaction with receipts
For details see https://docs.near.org/api/rpc/transactions#transaction-status-with-receipts
func (*Connection) GetTransactionDetailsWithWait ¶
func (c *Connection) GetTransactionDetailsWithWait(txHash, senderAccountId string, waitUntil TxExecutionStatus) (map[string]interface{}, error)
GetTransactionDetailsWithWait returns information about a single transaction after waiting for the specified execution status.
For details see https://docs.near.org/api/rpc/transactions#transaction-status
func (*Connection) SendTransaction ¶
func (c *Connection) SendTransaction(signedTransaction []byte) (map[string]interface{}, error)
SendTransaction sends a signed transaction and waits until the transaction is fully complete. Has a 10 second timeout.
For details see https://docs.near.org/docs/develop/front-end/rpc#send-transaction-await
func (*Connection) SendTransactionAsync ¶
func (c *Connection) SendTransactionAsync(signedTransaction []byte) (string, error)
SendTransactionAsync sends a signed transaction and immediately returns a transaction hash.
For details see https://docs.near.org/docs/develop/front-end/rpc#send-transaction-async
func (*Connection) ViewAccessKey ¶
func (c *Connection) ViewAccessKey(accountID, publicKey string) (map[string]interface{}, error)
ViewAccessKey returns information about a single access key for given accountID and publicKey. The publicKey must have a signature algorithm prefix (like "ed25519:").
For details see https://docs.near.org/docs/develop/front-end/rpc#view-access-key
func (*Connection) ViewAccessKeyList ¶
func (c *Connection) ViewAccessKeyList(accountID string) (map[string]interface{}, error)
ViewAccessKeyList returns all access keys for the given accountID.
For details see https://docs.near.org/docs/api/rpc/access-keys#view-access-key-list
type FunctionCall ¶
The FunctionCall action.
type FunctionCallPermission ¶
FunctionCallPermission encodes a NEAR function call permission (an access key permission).
type SignedTransaction ¶
type SignedTransaction struct { Transaction Transaction Signature Signature }
SignedTransaction encodes signed transactions for NEAR.
type Transaction ¶
type Transaction struct { SignerID string PublicKey utils.PublicKey Nonce uint64 ReceiverID string BlockHash [32]byte Actions []Action }
A Transaction encodes a NEAR transaction.
type TxExecutionStatus ¶
type TxExecutionStatus string
Transaction execution status
const ( // Transaction is waiting to be included into the block TxExecutionStatus_None TxExecutionStatus = "NONE" // Transaction is included into the block. The block may be not finalised yet TxExecutionStatus_Included TxExecutionStatus = "INCLUDED" // Transaction is included into the block + // All non-refund transaction receipts finished their execution. // The corresponding blocks for tx and each receipt may be not finalised yet TxExecutionStatus_ExecutedOptimistic TxExecutionStatus = "EXECUTED_OPTIMISTIC" // Transaction is included into finalised block TxExecutionStatus_IncludedFinal TxExecutionStatus = "INCLUDED_FINAL" // Transaction is included into finalised block + // All non-refund transaction receipts finished their execution. // The corresponding blocks for each receipt may be not finalised yet TxExecutionStatus_Executed TxExecutionStatus = "EXECUTED" // Transaction is included into finalised block + // Execution of all transaction receipts is finalised, including refund receipts TxExecutionStatus_Final TxExecutionStatus = "FINAL" TxExecutionStatus_Default = TxExecutionStatus_ExecutedOptimistic )
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
nearcall
nearcall allows to send large encoded arguments to a contract method.
|
nearcall allows to send large encoded arguments to a contract method. |
nearkey
nearkey generates a near node/account/validator key.
|
nearkey generates a near node/account/validator key. |
Package keystore implements an unencrypted file system key store.
|
Package keystore implements an unencrypted file system key store. |
Package utils implements helper functions for the Go NEAR API.
|
Package utils implements helper functions for the Go NEAR API. |