Categorygithub.com/gateway-fm/near-api-go
modulepackage
0.2.9
Repository: https://github.com/gateway-fm/near-api-go.git
Documentation: pkg.go.dev

# README

near-api-go

standard-readme compliant

A NEAR client written in Go

The goal of this project is to provide a fully featured NEAR cleint in Go. There is support for most NEAR RPC requests, including those that use signed transactions. Of course, there is room for improvement, especially with integration testing and a fully featured KeyStore, so please give it a spin and feel free to open a PR to help us improve the library.

We're currently relying on our fork of go-ethereum's JSON RPC client that adds support for named RPC parameters. That work is pending PR merge into their master branch.

Table of Contents

Install

go get github.com/gateway-fm/near-api-go

Usage

Import the required modules.

import (
  api "github.com/gateway-fm/near-api-go"
  "github.com/gateway-fm/near-api-go/keys"
  "github.com/gateway-fm/near-api-go/transaction"
  "github.com/gateway-fm/near-api-go/types"
  "github.com/ethereum/go-ethereum/rpc"
)

Configure and create an API client.

rpcClient, err := rpc.DialContext(ctx, "https://rpc.testnet.near.org")

keyPair, err := keys.NewKeyPairFromString(
  "ed25519:...",
)

config := &types.Config{
  RPCClient: rpcClient,
  Signer:    keyPair, // Currently we use a key pair directly as a signer.
  NetworkID: "testnet",
}

client, err := api.NewClient(config)

Interact with top level functions like CallFunction, for example. It can be used for calling non-signed "view" functions.

res, err := client.CallFunction(
  ctx,
  "<account id>",
  "myFunction",
  api.CallFunctionWithFinality("final"),
)

Most other functionality is provided by the Account sub module. For example, you can call state-modifying functions that are sent as signed transactions, and even include a deposit while you're at it.

deposit, ok := (&big.Int{}).SetString("1000000000000000000000000", 10)
res, err := client.Account("<client account id>").FunctionCall(
  ctx,
  <contract account id>,
  "myTxnFunction",
  transaction.FunctionCallWithArgs(map[string]interface{}{
    "arg1": value1, 
    "arg2": value2
  }),
  transaction.FunctionCallWithDeposit(*deposit),
)

Check out the API docs to see all that is possible.

API

https://pkg.go.dev/github.com/gateway-fm/near-api-go

Maintainers

@asutula

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2021 Textile

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

CallFunctionWithArgs specified the args to call the function with.
CallFunctionWithBlockHash specifies the block hash to call the function for.
CallFunctionWithBlockHeight specifies the block height to call the function for.
CallFunctionWithFinality specifies the finality to be used when calling the function.
DataChangesWithBlockHash specifies the block id to query data changes for.
DataChangesWithBlockHeight specifies the block id to query data changes for.
DataChangesWithFinality specifies the finality to be used when querying data changes.
DataChangesWithPrefix sets the data key prefix to query for.
NewClient creates a new Client.
ViewCodeWithBlockHash specifies the block hash to call the function for.
ViewCodeWithBlockHeight specifies the block height to call the function for.
ViewCodeWithFinality specifies the finality to be used when calling the function.

# Structs

CallFunctionResponse holds information about the result of a function call.
Cause holds information about the cause of a state change.
Change holds information about a state change of a key-value pair.
ChangeData holds information about a state change.
Client communicates with the NEAR API.
DataChangesResponse holds information about all data changes in a block.
EpochKickout struct.
Fisherman struct.
No description provided by the author
NodeStatusResponse holds information about node status.
SyncInfo holds information about the sync status of a node.
Validator struct.
ValidatorsResponse struct.
Version struct.
ViewCodeResponse holds information about contract code.

# Type aliases

CallFunctionOption controls the behavior when calling CallFunction.
DataChangesOption controls behavior when calling DataChanges.
Validators array.
ViewCodeOption controls the behavior when calling ViewCode.