WARNING: This library is still work in progress. While it covers about 90% of the use-cases, it does not have many batteries included.
go get github.com/eteu-technologies/near-api-go
What this library does not (and probably won't) provide:
TransactionSendAwait
What this library doesn't have yet:
EXPERIMENTAL_
)See cmd/ in this repo for more fully featured CLI examples. See NEARKit for a project which makes use of this API.
package main
import (
"context"
"fmt"
"github.com/eteu-technologies/near-api-go/pkg/client"
"github.com/eteu-technologies/near-api-go/pkg/client/block"
)
func main() {
rpc, err := client.NewClient("https://rpc.testnet.near.org")
if err != nil {
panic(err)
}
ctx := context.Background()
res, err := rpc.BlockDetails(ctx, block.FinalityFinal())
if err != nil {
panic(err)
}
fmt.Println("latest block: ", res.Header.Hash)
}
package main
import (
"context"
"fmt"
"github.com/eteu-technologies/near-api-go/pkg/client"
"github.com/eteu-technologies/near-api-go/pkg/types"
"github.com/eteu-technologies/near-api-go/pkg/types/action"
"github.com/eteu-technologies/near-api-go/pkg/types/key"
)
var (
sender = "mikroskeem.testnet"
recipient = "mikroskeem2.testnet"
senderPrivateKey = `ed25519:...`
)
func main() {
rpc, err := client.NewClient("https://rpc.testnet.near.org")
if err != nil {
panic(err)
}
keyPair, err := key.NewBase58KeyPair(senderPrivateKey)
if err != nil {
panic(err)
}
ctx := client.ContextWithKeyPair(context.Background(), keyPair)
res, err := rpc.TransactionSendAwait(ctx, sender, recipient, []action.Action{
action.NewTransfer(types.NEARToYocto(1)),
})
if err != nil {
panic(err)
}
fmt.Printf("https://rpc.testnet.near.org/transactions/%s\n", res.Transaction.Hash)
}
MIT