Examples

Initialization

1import Client
2 
3let conn = Connection(host: "http://127.0.0.1:4003/api")

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

1let blocks = Blocks(connection: conn)
2 
3var response: [String: Any]?
4 
5blocks.transactions(limit: 10, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

Retrieve a Block

1let blocks = Blocks(connection: conn)
2 
3var response: [String: Any]?
4 
5blocks.get(id: "validBlockId", completionHandler: { (response) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'id': 'validBlockId' ... }}

List All Transactions of a Block

1let blocks = Blocks(connection: conn)
2 
3var response: [String: Any]?
4 
5blocks.transactions(id: "validBlockId", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

Search All Blocks

1let blocks = Blocks(connection: conn)
2 
3var response: [String: Any]?
4 
5blocks.search(body: ["generatorPublicKey": "validPublicKey"], completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 100, ... }}

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

1let delegates = Delegates(connection: conn)
2 
3var response: [String: Any]?
4 
5delegates.all(limit: 20, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 20, ... }}

Retrieve a Delegate

1let delegates = Delegates(connection: conn)
2 
3var response: [String: Any]?
4 
5delegates.get(byName: "delegateName", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'username': 'delegateName', ... }}

List All Blocks of a Delegate

1let delegates = Delegates(connection: conn)
2 
3var response: [String: Any]?
4 
5delegates.blocks(byName: "delegateName", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 100, ... }}

List All Voters of a Delegate

1let delegates = Delegates(connection: conn)
2 
3var response: [String: Any]?
4 
5delegates.voters(byName: "delegateName", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

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

1let node = Node(connection: conn)
2 
3var response: [String: Any]?
4 
5node.configuration(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'nethash': '6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988', ... }}

Retrieve the Status

1let node = Node(connection: conn)
2 
3var response: [String: Any]?
4 
5node.status(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'synced': True, 'now': 6897158, 'blocksCount': -1}}

Retrieve the Syncing Status

1let node = Node(connection: conn)
2 
3var response: [String: Any]?
4 
5node.syncing(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'syncing': False, 'blocks': -1, 'height': 6897160, 'id': '12905037940821862953'}}

Retrieve the Node Fees

1let node = Node(connection: conn)
2 
3var response: [String: Any]?
4 
5node.fees(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {"meta":{"days":7, ...}}

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

1let peers = Peers(connection: conn)
2 
3var response: [String: Any]?
4 
5peers.all(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 100, ... }}

Retrieve a Peer

1let peers = Peers(connection: conn)
2 
3var response: [String: Any]?
4 
5peers.status(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'count': 20, ... }} # Need to changes

Transactions

The heart of any blockchain is formed by its 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

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.create(body: [transaction], completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> ...

Retrieve a Transaction

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.get(id: "validTransactionId", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> ...

List All Transactions

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.all(limit: 10, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

List All Unconfirmed Transactions

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.allUnconfirmed(limit: 10, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

Get Unconfirmed Transaction

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.getUnconfirmed(id: "validTransactionId", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> ...

Search Transactions

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.search(body: ["amount": 100000], completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

List Transaction Types

1let transactions = Transactions(connection: conn)
2 
3var response: [String: Any]?
4 
5transactions.types(completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {"data":{...}}

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

1let votes = Votes(connection: conn)
2 
3var response: [String: Any]?
4 
5votes.all(limit: 10, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

Retrieve a Vote

1let votes = Votes(connection: conn)
2 
3var response: [String: Any]?
4 
5votes.get(id: "validVoteId", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {...}}

Wallets

The wallet resource provides access to:

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

Retrieve All Wallets

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.all(limit: 10, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

Retrieve a Wallet

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.all(byAddress: "validWalletAddress", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'data': {'address': 'validWalletAddress' ... }}

List All Transactions of a Wallet

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.transactions(byAddress: "validWalletAddress", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

List All Received Transactions of a Wallet

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.receivedTransactions(byAddress: "validWalletAddress", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

List All Sent Transactions of a Wallet

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.sentTransactions(byAddress: "validWalletAddress", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

List All Votes of a Wallet

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.votes(byAddress: "validWalletAddress", completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

List All Top Wallets

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.top(limit: 10, completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}

Search All Wallets

1let wallets = Wallets(connection: conn)
2 
3var response: [String: Any]?
4 
5wallets.all(body: ["balance": 0], completionHandler: { (res) in
6 response = res
7 print(response)
8})
9 
10>>> {'meta': {'count': 10, ... }}
Last updated 11 months ago
Edit Page
Share:
2022 © ARK.io | All Rights Reserved
An ARK.io Product