near

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: CC0-1.0 Imports: 19 Imported by: 0

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

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

func NewAccount(key string, accountId string) *Account

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

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) 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 asynch NEAR function call.

func (*Account) Nonce added in v0.0.15

func (a *Account) Nonce() (int64, error)

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

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

SignAndSendTransactionAsync signs the given actions and sends it immediately

func (*Account) SignFunctionCall added in v0.0.15

func (a *Account) SignFunctionCall(contractID, methodName string,
	args map[string]interface{}, nonce int64, blockHash []byte,
	gas uint64, amount big.Int) ([]byte, []byte, error)

func (*Account) ViewFunction

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

ViewFunction calls the provided contract method as a readonly function

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
}

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

func (c *Connection) BlockHash() (string, error)

func (*Connection) BlockHashBase58 added in v0.0.15

func (c *Connection) BlockHashBase58() ([]byte, error)

func (*Connection) Chunk

func (c *Connection) Chunk(chunkId string) (map[string]interface{}, error)

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

func (c *Connection) View(contractName, methodName string, params map[string]interface{}) (map[string]interface{}, error)

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

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