Examples

Initialization

1package main
2 
3import (
4 "net/url"
5 
6 ark "github.com/ArkEcosystem/go-client/client"
7)
8 
9func main() {
10 // OPTIONAL: client accepts a *http.Client.
11 // Defaults to http.DefaultClient
12 client := ark.NewClient(nil)
13 
14 // OPTIONAL: You can specify the URL of your choice.
15 // Defaults to "https://dexplorer.ark.io:8443/api/"
16 url, _ := url.Parse("http://127.0.0.1:4003/api")
17 client.BaseURL = url
18}

Blocks

This service API grants access to the blocks resource . A block is a signed set of transactions created by a delegate and permanently committed to the ARK blockchain.

It is not possible to POST a block through the public API. Relay Nodes accept only blocks posted by a delegate at the correct time through the internal API.

List All Blocks

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Blocks.List(context.Background(), query)
3 
4>>> (*Blocks, *http.Response, error)

Retrieve a Block

1responseStruct, response, err := client.Blocks.List(context.Background(), validBlockId)
2 
3>>> (*GetBlock, *http.Response, error)

List All Transactions of a Block

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Blocks.List(context.Background(), validBlockId, query)
3 
4>>> *GetBlockTransactions, *http.Response, error

Search All Blocks

1query := &Pagination{Limit: 1}
2body := &BlocksSearchRequest{Id: "validBlockId"}
3responseStruct, response, err := client.Blocks.List(context.Background(), query)
4 
5>>> *Blocks, *http.Response, error

Delegates

The client SDK can be used to query the delegate resource .

A delegate is a regular wallet that has broadcast a registration transaction, acquired a sufficient number of votes, and has a Relay Node configured to forge new blocks through a forger module. At any time only 51 delegates are active. They are cost-efficient miners running the ARK network.

Voters are wallets which have broadcast a vote transaction on a delegate. A vote remains active until an un-vote transaction is sent (it does not have to be recast unless a wallet wishes to change from delegate). Voting for a delegate does not give the delegate access to the wallet nor does it lock the coins in it.

List All Delegates

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Delegates.List(context.Background(), query)
3 
4>>> (*Delegates, *http.Response, error)

Retrieve a Delegate

1responseStruct, response, err := client.Delegates.Get(context.Background(), "validDelegateId")
2 
3>>> (*GetDelegate, *http.Response, error)

List All Blocks of a Delegate

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Delegates.Blocks(context.Background(), "validDelegateId", query)
3 
4>>> (*GetDelegateBlocks, *http.Response, error)

List All Voters of a Delegate

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Delegates.Blocks(context.Background(), "validDelegateId", query)
3 
4>>> (*GetDelegateVoters, *http.Response, error)

Node

The ARK network consists of different anonymous nodes (servers), maintaining the public ledger, validating transactions and blocks and providing APIs. The node resource allows for querying the health and configurations of the node used by the instantiated client.

Retrieve the Configuration

1responseStruct, response, err := client.Node.Configuration(context.Background())
2 
3>>> *GetNodeConfiguration, *http.Response, error

Retrieve the Status

1responseStruct, response, err := client.Node.Status(context.Background())
2 
3>>> *GetNodeStatus, *http.Response, error

Retrieve the Syncing Status

1responseStruct, response, err := client.Node.Syncing(context.Background())
2 
3>>> *GetNodeSyncing, *http.Response, error

Peers

Each node is connected to a set of peers, which are Relay or Delegate Nodes as well. The peers resource provides access to all peers connected to our node.

Peers have made their Public API available for use; however for mission-critical queries and transaction posting you should use a node which is under your control. We provide a guide to setting up a Relay Node here .

List All Peers

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Peers.List(context.Background(), query)
3 
4>>> *Peers, *http.Response, error

Retrieve a Peer

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Peers.Get(context.Background(), "validIpAddress")
3 
4>>> *GetPeer, *http.Response, error

Transactions

The heart of any blockchain is formed by igo transactions; state-altering payloads signed by a wallet. Most likely you will be querying for transactions most often, using the transaction resource .

A transaction is the only object which may be posted by a non-delegate. It requires a signature from a wallet containing a sufficient amount of ARK.

Create a Transaction

1body := &CreateTransactionRequest{
2 Transactions: []Transaction{{
3 Id: "dummy",
4 BlockId: "dummy",
5 Type: 0,
6 Amount: 10000000,
7 Fee: 10000000,
8 Sender: "dummy",
9 Recipient: "dummy",
10 Signature: "dummy",
11 VendorField: "dummy",
12 Confirmations: 10,
13 Timestamp: Timestamp{
14 Epoch: 40505460,
15 Unix: 1530606660,
16 Human: "2018-07-03T08:31:00Z",
17 },
18 }},
19 }
20responseStruct, response, err := client.Transactions.Create(context.Background(), query)
21 
22>>> *CreateTransaction, *http.Response, error

Retrieve a Transaction

1responseStruct, response, err := client.Transactions.Get(context.Background(), "validTxId")
2 
3>>> *GetTransaction, *http.Response, error

List All Transactions

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Transactions.List(context.Background(), query)
3 
4>>> *Transactions, *http.Response, error

List All Unconfirmed Transactions

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Transactions.ListUnconfirmed(context.Background(), query)
3 
4>>> *Transactions, *http.Response, error

Get Unconfirmed Transaction

1responseStruct, response, err := client.Transactions.GetUnconfirmed(context.Background(), "validTxId")
2 
3>>> *GetTransaction, *http.Response, error

Search Transactions

1query := &Pagination{Limit: 1}
2body := &TransactionsSearchRequest{Id: "validTxId"}
3responseStruct, response, err := client.Transactions.Search(context.Background(), query)
4 
5>>> *Transactions, *http.Response, error

List Transaction Types

1responseStruct, response, err := client.Transactions.Types(context.Background())
2 
3>>> *TransactionTypes, *http.Response, error

Votes

A vote is a transaction sub-type, where the asset field contains a votes object and the transaction.type is 3.

List All Votes

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Votes.List(context.Background(), query)
3 
4>>> *Transactions, *http.Response, error

Retrieve a Vote

1responseStruct, response, err := client.Votes.Get(context.Background(), "validVoteId")
2 
3>>> *GetTransaction, *http.Response, error

Wallets

The wallet resource provides access to:

  • Wallets.
  • Incoming and outgoing transactions per wallet.
  • Each wallet’s votes.

Retrieve All Wallets

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Wallets.List(context.Background(), query)
3 
4>>> *Wallets, *http.Response, error

Retrieve a Wallet

1responseStruct, response, err := client.Wallets.Get(context.Background(), "validVoteId")
2 
3>>> *GetWallet, *http.Response, error

List All Transactions of a Wallet

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Wallets.Transactions(context.Background(), query)
3 
4>>> *Transactions, *http.Response, error

List All Received Transactions of a Wallet

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Wallets.ReceivedTransactions(context.Background(), query)
3 
4>>> *Transactions, *http.Response, error

List All Sent Transactions of a Wallet

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Wallets.SentTransactions(context.Background(), query)
3 
4>>> *Transactions, *http.Response, error

List All Votes of a Wallet

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Wallets.Votes(context.Background(), "validWalletId", query)
3 
4>>> *Transactions, *http.Response, error

List All Top Wallets

1query := &Pagination{Limit: 1}
2responseStruct, response, err := client.Wallets.Top(context.Background(), query)
3 
4>>> *Wallets, *http.Response, error

Search All Wallets

1query := &Pagination{Limit: 1}
2body := &WalletsSearchRequest{Address: "validAddress"}
3responseStruct, response, err := client.Wallets.List(context.Background(), query, body)
4 
5>>> *Wallets, *http.Response, error
Last updated 3 years ago
Edit Page
Share: