near

package module
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: CC0-1.0 Imports: 20 Imported by: 5

README

near-api-go

Go Reference CI Go Report Card

A Go library for development of DApps on the NEAR platform.

There is also a JavaScript/TypeScript implementation.

Installation

go get -u -v github.com/aurora-is-near/near-api-go

(How to install Go. Add $GOPATH/bin to your $PATH.)

Documentation

Overview

Package near allows to interact with the NEAR platform via RPC calls.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func GetTransactionLastResult(txResult map[string]interface{}) (interface{}, error)

GetTransactionLastResult decodes the last transaction result from a JSON map and tries to deterimine if we have an error condition.

Types

type AccessKey added in v0.0.4

type AccessKey struct {
	Nonce      uint64
	Permission AccessKeyPermission
}

AccessKey encodes a NEAR access key.

type AccessKeyPermission added in v0.0.4

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 access credentials for a NEAR account.

func LoadAccount

func LoadAccount(c *Connection, cfg *Config, receiverID string) (*Account, error)

LoadAccount loads the credential for the receiverID account, to be used via connection c, and returns it.

func (*Account) AddKeys added in v0.0.14

func (a *Account) AddKeys(
	publicKeys ...utils.PublicKey,
) (map[string]interface{}, error)

AddKeys adds the given publicKeys to the account with full access.

func (*Account) CreateAccount added in v0.0.4

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

func (a *Account) DeleteAccount(
	beneficiaryID string,
) (map[string]interface{}, error)

DeleteAccount deletes the account and sends the remaining Ⓝ balance to the account beneficiaryID.

func (*Account) DeleteKeys added in v0.0.14

func (a *Account) DeleteKeys(
	publicKeys ...utils.PublicKey,
) (map[string]interface{}, error)

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 added in v0.0.13

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 added in v0.0.13

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 added in v0.0.13

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 added in v0.0.13

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 added in v0.0.13

func (a *Account) GetVerifiedAccessKeys() []string

GetVerifiedAccessKeys verifies and returns the public keys of the access keys

func (*Account) SendMoney

func (a *Account) SendMoney(
	receiverID string,
	amount big.Int,
) (map[string]interface{}, error)

SendMoney sends amount NEAR from account to receiverID.

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 added in v0.0.13

func (a *Account) SignAndSendTransactionAsync(
	receiverID string,
	actions []Action,
) (string, error)

SignAndSendTransactionAsync signs the given actions and sends it immediately

func (*Account) SignAndSendTransactionAsyncWithKey added in v0.0.13

func (a *Account) SignAndSendTransactionAsyncWithKey(
	receiverID string,
	publicKey string,
	actions []Action,
) (string, error)

SignAndSendTransactionAsyncWithKey signs the given actions and sends it immediately

func (*Account) SignAndSendTransactionWithKey added in v0.0.13

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 added in v0.0.13

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 added in v0.0.13

func (a *Account) ViewAccessKey(publicKey string) (map[string]interface{}, error)

func (*Account) ViewFunction added in v0.0.13

func (a *Account) ViewFunction(accountId, methodName string, argsBuf []byte, options *int64) (interface{}, error)

ViewFunction calls the provided contract method as a readonly function

func (*Account) ViewNonce added in v0.0.13

func (a *Account) ViewNonce(publicKey string) (uint64, error)

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 AddKey

type AddKey struct {
	PublicKey utils.PublicKey
	AccessKey AccessKey
}

The AddKey action.

type Config

type Config struct {
	NetworkID                string
	NodeURL                  string
	KeyPath                  string
	FunctionKeyPrefixPattern string
}

A Config for the NEAR network.

func GetConfig

func GetConfig() *Config

GetConfig returns the NEAR network config depending on the setting of the environment variable NEAR_ENV.

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) GetAccountState added in v0.0.10

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 added in v0.0.17

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 added in v0.0.17

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) GetContractCode added in v0.0.10

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 added in v0.0.10

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 added in v0.0.15

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 added in v0.0.16

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) 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 added in v0.0.12

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 DeleteAccount

type DeleteAccount struct {
	BeneficiaryID string
}

The DeleteAccount action.

type DeleteKey

type DeleteKey struct {
	PublicKey utils.PublicKey
}

The DeleteKey action.

type DeployContract

type DeployContract struct {
	Code []byte
}

The DeployContract action.

type FunctionCall

type FunctionCall struct {
	MethodName string
	Args       []byte
	Gas        uint64
	Deposit    big.Int // u128
}

The FunctionCall action.

type FunctionCallPermission added in v0.0.4

type FunctionCallPermission struct {
	Allowance   *big.Int
	ReceiverId  string
	MethodNames []string
}

FunctionCallPermission encodes a NEAR function call permission (an access key permission).

type Signature

type Signature struct {
	KeyType uint8
	Data    [64]byte
}

A Signature used for signing transaction.

type SignedTransaction

type SignedTransaction struct {
	Transaction Transaction
	Signature   Signature
}

SignedTransaction encodes signed transactions for NEAR.

type Stake

type Stake struct {
	Stake     big.Int // u128
	PublicKey utils.PublicKey
}

The Stake action.

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 Transfer

type Transfer struct {
	Deposit big.Int // u128
}

The Transfer action.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL