Skip to content
Snippets Groups Projects
api.md 40.7 KiB
Newer Older
Androlo's avatar
Androlo committed
# Eris DB web APIs (draft)

androlo's avatar
androlo committed
### for eris-db version 0.11.x
Androlo's avatar
Androlo committed

Eris DB allows remote access to its functionality over http and websocket. It currently supports [JSON-RPC 2.0](http://www.jsonrpc.org/specification), and REST-like http. There is also javascript bindings available in the [erisdb-js](TODO) library.
Androlo's avatar
Androlo committed

## TOC

- [HTTP Requests](#http-requests)
Androlo's avatar
Androlo committed
- [JSON-RPC 2.0](#json-rpc)
- [REST-like HTTP](#rest-like)
- [Common objects and formatting](#formatting-conventions)
- [Event-system](#event-system)
- [Methods](#methods)
androlo's avatar
androlo committed
- [NameReg](#namereg)
Androlo's avatar
Androlo committed
- [Filters](#queries-filters)
Androlo's avatar
Androlo committed

<a name="http-requests"></a>
## HTTP Requests

The only data format supported is JSON. All post requests needs to use `Content-Type: application/json`. The charset flag is not supported (json is utf-8 encoded by default).

Androlo's avatar
Androlo committed
<a name="json-rpc"></a>
## JSON RPC 2.0

Androlo's avatar
Androlo committed
The default endpoints for JSON-RPC (2.0) is `/rpc` for http based, and `/socketrpc` for websocket. The namespace for the JSON-RPC service is `erisdb`.
Androlo's avatar
Androlo committed

It does not yet support notifications or batched requests.

Androlo's avatar
Androlo committed
### Objects

##### Errors

```
PARSE_ERROR      = -32700
INVALID_REQUEST  = -32600
METHOD_NOT_FOUND = -32601
INVALID_PARAMS   = -32602
INTERNAL_ERROR   = -32603
```

#####Request
Androlo's avatar
Androlo committed
```
{
	jsonrpc: <string>
	method:  <string>
	params:  <Object>
	id:      <string>
}
```

#####Response
Androlo's avatar
Androlo committed
```
{
	jsonrpc: <string>
	id:      <string>
	result:  <Object>
	error:   <Error>
}
```

#####Error
Androlo's avatar
Androlo committed
```
{
    code:    <number>
    message: <string>
}
```
Androlo's avatar
Androlo committed
Id can be any string value. Parameters are named, and wrapped in objects. Also, params, result and error params may be `null`.

#####Example

Androlo's avatar
Androlo committed
Request:

Androlo's avatar
Androlo committed
```
{
	jsonrpc: "2.0", 
	method: "erisdb.getAccount", 
	params: {address: "37236DF251AB70022B1DA351F08A20FB52443E37"}, 
	id="25"
}
```

Response:
Androlo's avatar
Androlo committed
```
{
    address: "37236DF251AB70022B1DA351F08A20FB52443E37",
    pub_key: null,
    sequence: 0,
    balance: 110000000000,
    code: "",
    storage_root: ""
}
```

<a name="rest-like"></a>
Androlo's avatar
Androlo committed
## REST-like HTTP
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
The REST-like API provides the typical endpoint structure i.e. endpoints are named as resources, parameters can be put in the path, and queries are used for filtering and such. It is not fully compatible with REST; partly because some GET requests can contain sizable input so POST is used instead. There are also some modeling issues but those will most likely be resolved before version 1.0.
Androlo's avatar
Androlo committed

<a name="formatting-conventions"></a>
##Common objects and formatting

Androlo's avatar
Androlo committed
This section contains some common objects and explanations of how they work.
Androlo's avatar
Androlo committed
  
###Numbers and strings

Numbers are always numbers, and never strings. This is different from Ethereum where currency values are so high they need string representations. The only thing hex strings are used for is to represent byte arrays. 

Androlo's avatar
Androlo committed
Hex strings are never prefixed.
Androlo's avatar
Androlo committed

#####Examples

```
"some_number_field" : 5892,
"another_number_field" : 0x52
"hex_string" : "37236DF251AB70022B1DA351F08A20FB52443E37"
```

###Keys and addresses

Public and Private keys in JSON data are either null, or on the form: `[type, hex]`, where `type` is the [public](https://github.com/tendermint/tendermint/blob/master/account/pub_key.go), or [private](https://github.com/tendermint/tendermint/blob/master/account/pub_key.go) key type, and `hex` is the hex-string representation of the key bytes.

Androlo's avatar
Androlo committed
- A `public address` is a 20 byte hex string.
- A `public key` is a 32 byte hex string.
- A `private key` is a 64 byte hex string.
Androlo's avatar
Androlo committed

#####WARNING

**When using a client-server setup, do NOT send public keys over non-secure connections. The only time this is fine is during development when the keys are nothing but test data and does not protect anything of value. Normally they should either be kept locally and used to sign transactions locally, held on the server where the blockchain client is running, or be passed over secure channels.**

#####Examples

A public address: `"37236DF251AB70022B1DA351F08A20FB52443E37"`

The corresponding Ed25519 public key: `[1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"]`

The corresponding Ed25519 private key: `[1, "6B72D45EB65F619F11CE580C8CAED9E0BADC774E9C9C334687A65DCBAD2C4151CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"]`

<a name="the-transaction-types"></a>
###The transaction types

androlo's avatar
androlo committed
These are the types of transactions. Note that in DApp programming you would only use the `CallTx`, and maybe `NameTx`.
Androlo's avatar
Androlo committed

####SendTx
Androlo's avatar
Androlo committed
```
{
	inputs:  [<TxInput>]
	outputs: [<TxOutput>]
}
```

####CallTx
Androlo's avatar
Androlo committed
```
{
	input:     <TxInput>
	address:   <string>
	gas_limit: <number>
	fee:       <number>
	data:      <string>
}
```

####NameTx
Androlo's avatar
Androlo committed
```
{
Androlo's avatar
Androlo committed
	input:  <TxInput>
	name:   <string>
	data:   <string>
	amount: <number>
	fee:    <number>
Androlo's avatar
Androlo committed
}
```

####BondTx
Androlo's avatar
Androlo committed
```
{
	pub_key:   <PubKey>
	signature: <string>
	inputs:    [<TxInput>]
	unbond_to: [<TxOutput>]
}
```

####UnbondTx
Androlo's avatar
Androlo committed
```
{
	address:   <string>
	height:    <number>
	signature: <string>
}
```

####RebondTx
Androlo's avatar
Androlo committed
```
{
	address:   <string>
	height:    <number>
	signature: <string>
}
```

####DupeoutTx
Androlo's avatar
Androlo committed
```
{
	address: <string>
	vote_a:  <Vote>
	vote_b:  <Vote>
}
```

These are the support types that are referenced in the transactions:

####TxInput
Androlo's avatar
Androlo committed
```
{
	address:   <string>
	amount:    <number>
	sequence:  <number>
	signature: <string>
	pub_key:   <string>
}
```

####TxOutput
Androlo's avatar
Androlo committed
```
{
	address: <string>
	amount:  <number>
}
```

####Vote

```
{
	height:     <number>
	type:       <number>
	block_hash: <string>
	block_parts: {
		total: <number>
		hash:  <string>
	}
	signature: <string>
}
```

<a name="event-system"></a>
##Event system

Androlo's avatar
Androlo committed
Tendermint events can be subscribed to regardless of what connection type is used. There are three methods for this:

- [EventSubscribe](#event-subscribe) is used to subscribe to a given event, using an event-id string as argument. The response will contain a `subscription ID`, which can be used to close down the subscription later, or poll for new events if using HTTP. More on event-ids below.
- [EventUnsubscribe](#event-unsubscribe) is used to unsubscribe to an event. It requires you to pass the `subscription ID` as an argument.
- [EventPoll](#event-poll) is used to get all the events that has accumulated since the last time the subscription was polled. It takes the `subscription ID` as a parameter. NOTE: This only works over HTTP. Websocket connections will automatically receive events as they happen. They are sent as regular JSON-RPC 2.0 responses with the `subscriber ID` as response id.
 
There is another slight difference between polling and websocket, and that is the data you receive. If using sockets, it will always be one event at a time, whereas polling will give you an array of events.

### Event types

These are the type of events you can subscribe to. 

The "Account" events are triggered when someone transacts with the given account, and can be used to keep track of account activity. 

NewBlock and Fork happens when a new block is committed or a fork happens, respectively. 

The other events are directly related to consensus. You can find out more about the Tendermint consensus system in the Tendermint [white paper](http://tendermint.com/docs/tendermint.pdf). There is also information in the consensus [sources](https://github.com/tendermint/tendermint/blob/master/consensus/state.go), although a normal user would not be concerned with the consensus mechanisms, but would mostly just listen to account- and perhaps block-events. 

#### Account Input

This notifies you when an account is receiving input.

Event ID: `Acc/<address>/Input`

Example: `Acc/B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7/Input` will subscribe to input events from the account with address: B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7.

Event object:

```
{
	tx:        <Tx>
	return:    <string>
	exception: <string>
}
```

#### Account Output

This notifies you when an account is yielding output.

Event ID: `Acc/<address>/Output`

Example: `Acc/B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7/Output` will subscribe to output events from the account with address: B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7.

Event object:

```
<Tx>
```

androlo's avatar
androlo committed
#### Account Call
androlo's avatar
androlo committed
This notifies you when an account is the target of a call. This event is emitted when `CallTx`s (transactions) that target the given account has been finalized. It is possible to listen to this event when creating new contracts as well; it will fire when the transaction is committed (or not, in which case the 'exception' field will explain why it failed). 
androlo's avatar
androlo committed
**NOTE: The naming here is a bit unfortunate. Ethereum uses 'transaction' for (state-changing) transactions to a contract account, and 'call' for read-only calls like is used for accessor functions and such. Tendermint on the other hand, which uses many types of transactions uses 'CallTx' for a transaction made to a contract account, since it calls the code in that contract, and refers to these simply as 'calls'. Read-only calls is normally referred to as 'simulated calls'.** 
androlo's avatar
androlo committed
Event ID: `Acc/<address>/Call`

Example: `Acc/B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7/Call` will subscribe to events from the account with address: B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7.
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
```
{
	call_data: {
		caller: <string>
    	callee: <string>
    	data:   <string>
    	value:  <number>
    	gas:    <number>
	}
	origin:     <string>
	tx_id:      <string>
	return:     <string>
	exception:  <string>
}
```

Androlo's avatar
Androlo committed
#### Log

This notifies you when the VM fires a log-event. This happens for example when a solidity event is fired.

Event ID: `Log/<address>`

Example: `Log/B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7/Input` will subscribe to all log events from the account with address: B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7.

type Log struct {
	Address Word256
	Topics  []Word256
	Data    []byte
	Height  uint64
}

Event object:

```
{
	address: <string>
	topics:  []<string>
	data:    <string>
	height   <number>
}
```

`address` is the address of the account that created the log event.

`topics` is the parameters listed as topics. In a (named) Solidity event they would be the hash of the event name, followed by each param with the `indexed` modifier.

`data` the data. In a Solidity event these would be the params without the `indexed` modifier.

`height` is the current block-height.

Androlo's avatar
Androlo committed
#### New Block

This notifies you when a new block is committed.

Event ID: `NewBlock`

Event object:

```
<Block>
```

#### Fork

This notifies you when a fork event happens.

Event ID: `Fork`

Event object:
Androlo's avatar
Androlo committed

TODO
Androlo's avatar
Androlo committed
```
<Block>
```

#### Bond

This notifies you when a bond event happens.

Event ID: `Bond`

Event object:

```
<Tx>
```

#### Unbond

This notifies you when an unbond event happens.

Event ID: `Unbond`

Event object:

```
<Tx>
```

#### Rebond

This notifies you when a rebond event happens.

Event ID: `Rebond`

Event object:

```
<Tx>
```

#### Dupeout

This notifies you when a dupeout event happens.

Event ID: `Dupeout`

Event object:

```
<Tx>
```
Androlo's avatar
Androlo committed

androlo's avatar
androlo committed
<a name="namereg">
### Name-registry

The name-registry is a built-in key-value store that allow you to store bulk data in a different storage. It is currently regulated by the use of Tendermint tokens. The cost of storing some `Data` in the name-registry is this:

```
TotalCost = Cost*NumberOfBlocks

Cost = CostPerBlock*CostPerByte*(length(Data) + 32)

CostPerBlock = 1

CostPerByte = 1

length(Data) = the number of bytes in 'Data'.
```

To pay this cost you use the `amount` field in the namereg transaction. If you want to store a 3 kb document for 10 blocks, the total cost would be `1*1*(3000 + 32)*10 = 30320` tendermint tokens.

See the [TransactNameReg](#transact-name-reg) method for more info about adding entries to the name-registry, and the methods in the [Name-registry](#name-registry) for accessing them.

Androlo's avatar
Androlo committed
<a name="methods"></a>
##Methods

###Accounts 
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [GetAccounts](#get-accounts) | erisdb.getAccounts | GET | `/accounts` |
| [GetAccount](#get-account) | erisdb.getAccount | GET | `/accounts/:address` |
| [GetStorage](#get-storage) | erisdb.getStorage | GET | `/accounts/:address/storage` |
| [GetStorageAt](#get-storage-at) | erisdb.getStorageAt | GET | `/accounts/:address/storage/:key` |

###Blockchain
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [GetBlockchainInfo](#get-blockchain-info) | erisdb.getBlockchainInfo | GET | `/blockchain` |
| [GetChainId](#get-chain-id) | erisdb.getChainId | GET | `/blockchain/chain_id` |
| [GetGenesisHash](#get-genesis-hash) | erisdb.getGenesisHash | GET | `/blockchain/genesis_hash` |
| [GetLatestBlockHeight](#get-latest-block-height) | erisdb.getLatestBlockHeight | GET | `/blockchain/latest_block/height` |
| [GetLatestBlock](#get-latest-block) | erisdb.getLatestBlock | GET | `/blockchain/latest_block` |
| [GetBlocks](#get-blocks) | erisdb.getBlocks | GET | `/blockchain/blocks` |
| [GetBlock](#get-block) | erisdb.getBlock | GET | `/blockchain/blocks/:height` |

###Consensus
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [GetConsensusState](#get-consensus-state) | erisdb.getConsensusState | GET | `/consensus` |
| [GetValidators](#get-validators) | erisdb.getValidators | GET | `/consensus/validators` |

###Events
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [EventSubscribe](#event-subscribe) | erisdb.eventSubscribe | POST | `/event_subs` |
| [EventUnsubscribe](#event-unsubscribe) | erisdb.eventUnsubscribe | DELETE | `/event_subs/:id` |
| [EventPoll](#event-poll) | erisdb.eventPoll | GET | `/event_subs/:id` |

Androlo's avatar
Androlo committed
###Name-registry
| Name | RPC method name | HTTP method | HTTP endpoint |
| :--- | :-------------- | :---------: | :------------ |
| [GetNameRegEntry](#get-namereg-entry) | erisdb.getNameRegEntry | GET | `/namereg/:key` |
| [GetNameRegEntries](#get-namereg-entries) | erisdb.getNameRegEntries | GET | `/namereg` |

Androlo's avatar
Androlo committed
###Network
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [GetNetworkInfo](#get-network-info) | erisdb.getNetworkInfo | GET | `/network` |
Androlo's avatar
Androlo committed
| [GetClientVersion](#get-client-version) | erisdb.getClientVersion | GET | `/network/client_version` |
Androlo's avatar
Androlo committed
| [GetMoniker](#get-moniker) | erisdb.getMoniker | GET | `/network/moniker` |
| [IsListening](#is-listening) | erisdb.isListening | GET | `/network/listening` |
| [GetListeners](#get-listeners) | erisdb.getListeners | GET | `/network/listeners` |
| [GetPeers](#get-peers) | erisdb.getPeers | GET | `/network/peers` |
| [GetPeer](#get-peer) | erisdb.getPeer | GET | `/network/peer/:address` |

androlo's avatar
androlo committed
NOTE: Get peer is not fully implemented.

Androlo's avatar
Androlo committed
###Transactions
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [BroadcastTx](#broadcast-tx) | erisdb.broadcastTx | POST | `/txpool` |
Androlo's avatar
.  
Androlo committed
| [GetUnconfirmedTxs](#get-unconfirmed-txs) | erisdb.getUnconfirmedTxs | GET | `/txpool` |
Androlo's avatar
Androlo committed

###Code execution
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [Call](#call) | erisdb.call | POST | `/calls` |
| [CallCode](#call-code) | erisdb.callCode | POST | `/codecalls` |
Androlo's avatar
Androlo committed

####Unsafe
Androlo's avatar
Androlo committed
| Name | RPC method name | HTTP method | HTTP endpoint |
Androlo's avatar
Androlo committed
| :--- | :-------------- | :---------: | :------------ |
| [Transact](#transact) | erisdb.transact | POST | `/unsafe/txpool` |
androlo's avatar
androlo committed
| [Transact](#transact-and-hold) | erisdb.transactAndHold | POST | `/unsafe/txpool?hold=true` |
Androlo's avatar
Androlo committed
| [TransactNameReg](#transact-name-reg) | erisdb.transactNameReg | POST | `/unsafe/namereg/txpool` |
Androlo's avatar
Androlo committed
| [GenPrivAccount](#gen-priv-account) | erisdb.genPrivAccount | GET | `/unsafe/pa_generator` |

Here are the catagories.

* [Accounts](#accounts)
* [BlockChain](#blockchain)
* [Consensus](#consensus)
* [Events](#events)
Androlo's avatar
Androlo committed
* [Name-registry](#name-registry)
Androlo's avatar
Androlo committed
* [Network](#network)
* [Transactions](#transactions)
* [Code Execution (calls)](#calls)
* [Unsafe](#unsafe)

In the case of **JSON-RPC**, the parameters are wrapped in a request object, and the return value is wrapped in a response object.

Androlo's avatar
Androlo committed
In the case of **REST-like HTTP** GET requests, the params (and query) is provided in the url. If it's a POST, PATCH or PUT request, the parameter object should be written to the body of the request as JSON. It is normally the same params object as in JSON-RPC.
Androlo's avatar
Androlo committed

**Unsafe** is methods that require a private key to be sent either to or from the client, and should therefore be used only during development/testing, or with extreme care. They may be phased out entirely.

<a name="accounts"></a>
###Accounts 

***

<a name="get-accounts"></a>
####GetAccounts 

Get accounts will return a list of accounts. If no filtering is used, it will return all existing accounts.

#####HTTP

Androlo's avatar
Androlo committed
Method: GET
Androlo's avatar
Androlo committed

Endpoint: `/accounts`

#####JSON-RPC

Method: `erisdb.getAccounts`

Parameter:

```
{
	filters: [<FilterData>]
}
```

Androlo's avatar
Androlo committed
##### Filters

| Field | Underlying type | Ops | Example Queries |
| :---- | :-------------- | :-- | :-------------- |
| `balance` | uint64 | `<`, `>`, `<=`, `>=`, `==` | `q=balance:<=11` |
| `code` | byte[] | `==`, `!=` | `q=code:1FA872` |
Androlo's avatar
Androlo committed

#####Return value
Androlo's avatar
Androlo committed
{
	accounts: [<Account>]
}
```

#####Additional info

See GetAccount below for more info on the `Account` object.

Androlo's avatar
Androlo committed
See the section on [Filters](#queries-filters) for info on the `FilterData` object.
Androlo's avatar
Androlo committed

***

<a name="get-account"></a>
####GetAccount

Get an account by its address.

#####HTTP

Method: GET 

Endpoint: `/accounts/:address`

Params: The public `address` as a hex string.


#####JSON-RPC

Method: `erisdb.getAccount`

Parameter:

```
{
	address: <string>
}
```

#####Return value
Androlo's avatar
Androlo committed
{
	address:      <string>
	pub_key:      <PubKey>
	sequence:     <number>
	balance:      <number>
	code:         <string>
	storage_root: <string>
}
```

`address` is a public address.
`pub_key` is a public key.

#####Additional info

Sequence is sometimes referred to as the "nonce".

There are two types of objects used to represent accounts, one is public accounts (like the one here), the other is private accounts, which only holds information about an accounts address, public and private key.

***

<a name="get-storage"></a>
####GetStorage 

Get the complete storage of a contract account. Non-contract accounts has no storage. 

NOTE: This is mainly used for debugging. In most cases the storage of an account would be accessed via public accessor functions defined in the contracts ABI.

#####HTTP

Method: GET 

Endpoint: `/accounts/:address/storage`

Params: The public `address` as a hex string.


#####JSON-RPC

Method: `erisdb.getStorage`

Parameter:

```
{
	address: <string>
}
```

#####Return value
Androlo's avatar
Androlo committed
{
	storage_root:  <string>
	storage_items: [<StorageItem>]
}
```

`storage_root` is a public address.
See `GetStorageAt` below for more info on the `StorageItem` object.

***

<a name="get-storage-at"></a>
####GetStorageAt

Get a particular entry in the storage of a contract account. Non-contract accounts has no storage. 

NOTE: This is mainly used for debugging. In most cases the storage of an account would be accessed via public accessor functions defined in the contracts ABI.

#####HTTP

Method: GET

Endpoint: `/accounts/:address/storage/:key`

Params: The public `address` as a hex string, and the `key` as a hex string.

#####JSON-RPC

Method: `erisdb.getStorageAt`

Parameter:

```
{
	address: <string>
	key:     <string>
}
```

#####Return value
Androlo's avatar
Androlo committed
{
	key:   <string>
	value: <string>
}
```

Both `key` and `value` are hex strings.

***

<a name="blockchain"></a>
###Blockchain

***

<a name="get-blockchain-info"></a>
####GetBlockchainInfo

Get the current state of the blockchain. This includes things like chain-id and latest block height. There are individual getters for all fields as well. 

#####HTTP

Method: GET

Endpoint: `/blockchain`

#####JSON-RPC

Method: `erisdb.getBlockchainInfo`

Parameter: -

#####Return value
Androlo's avatar
Androlo committed
{
	chain_id:            <string>
	genesis_hash:        <string>
	latest_block:        <BlockMeta>
	latest_block_height: <number> 
}
```

#####Additional info

`chain_id` is the name of the chain.
`genesis_hash` is a 32 byte hex-string. It is the hash of the genesis block, which is the first block on the chain.
`latest_block` contains block metadata for the latest block. See the [GetBlock](#get-block) method for more info.
`latest_block_height` is the height of the latest block, and thus also the height of the entire chain.

The block *height* is sometimes referred to as the block *number*.

See [GetBlock](#get-block) for more info on the `BlockMeta` type.

***

<a name="get-chain-id"></a>
####GetChainId

Get the chain id.

#####HTTP

Method: GET

Endpoint: `/blockchain/chain_id`

#####JSON-RPC

Method: `erisdb.getChainId`

Parameter: -

#####Return value
Androlo's avatar
Androlo committed
{
	chain_id:            <string>
}
```
***

<a name="get-genesis-hash"></a>
####GetGenesisHash

Get the genesis hash. This is a 32 byte hex-string representation of the hash of the genesis block. The genesis block is the first block on the chain.

#####HTTP

Method: GET

Endpoint: `/blockchain/genesis_hash`

#####JSON-RPC

Method: `erisdb.getGenesisHash`

Parameter: -

#####Return value
Androlo's avatar
Androlo committed
{
	genesis_hash:        <string> 
}
```

***

<a name="get-latest-block-height"></a>
####GetLatestBlockHeight

Get the height of the latest block. This would also be the height of the entire chain.

#####HTTP

Method: GET

Endpoint: `/blockchain/latest_block/height`

#####JSON-RPC

Method: `erisdb.getLatestBlockHeight`

Parameter: -

#####Return value
Androlo's avatar
Androlo committed
{
	latest_block_height: <number> 
}
```

***

<a name="get-latest-block"></a>
####GetLatestBlock

Gets the block that was added to the chain most recently. 

#####HTTP

Method: GET

Endpoint: `/blockchain/latest_block`

#####JSON-RPC

Method: `erisdb.getLatestBlock`

Parameter: -

#####Return value
Androlo's avatar
Androlo committed
{
	latest_block:        <BlockMeta> 
}
```

#####Additional info

See [GetBlock](#get-block) for more info on the `BlockMeta` type. 

***

<a name="get-blocks"></a>
####GetBlocks

Get a series of blocks from the chain. 

#####HTTP

Method: GET

Endpoint: `/blockchain/blocks`

#####JSON-RPC

Method: `erisdb.getBlocks`

Parameter: 

```
{
	filters: [<FilterData>]
}
```

Androlo's avatar
Androlo committed
##### Filters

| Field | Underlying type | Ops | Example Queries |
| :---- | :-------------- | :-- | :-------------- |
| `height` | uint | `<`, `>`, `<=`, `>=`, `==` | `q=height:>4`, `q=height:10..*` |



Androlo's avatar
Androlo committed
#####Return value

Androlo's avatar
Androlo committed
```
Androlo's avatar
Androlo committed
{
	min_height:  <number>
	max_height:  <number>
	block_metas: [<BlockMeta>]
}
```

The `BlockMeta` object:

```
{
	hash: <string>
	header: {
		chain_id:        <string>
		height:          <number>
		time:            <string>
		fees:            <number>
		num_txs:         <number>
		last_block_hash: <string>
		last_block_parts: {
			total: <number>
			hash:  <string>
		}
		state_hash: <string>
	}
	parts: {
		total: <number>
		hash:  <string>
	}
}
```

#####Additional info

TODO

Androlo's avatar
Androlo committed
See the section on [Filters](#queries-filters) for info on the `FilterData` object.
Androlo's avatar
Androlo committed

`min_height` and `max_height` is the two actual values used for min and max height when fetching the blocks. The reason they are included is because the heights might have been modified, like for example when the blockchain height is lower then the max height provided in the query.

See [GetBlock](#get-block) for more info on the `BlockMeta` type. 

***

<a name="get-block"></a>
####GetBlock

Get the block at the given height. 

#####HTTP

Method: GET

Endpoint: `/blockchain/block/:number`

#####JSON-RPC

Method: `erisdb.getBlock`

Parameter:

Androlo's avatar
Androlo committed
```
Androlo's avatar
Androlo committed
{
	height: <number>