# Blockchain

## CGP

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/cgp`

Get the current CGP status of the Blockchain

{% tabs %}
{% tab title="200 " %}

```
{
    "interval": 2391,
    "allocation": 90,
    "payout": {
        "recipient": "tzn1q7fnh47xftwr2zpxtpxepf022l9u5k0kusahactcn099vlumxy58s4kzzx6",
        "spendlist": [{
            "asset": "00",
            "amount": "12300000000"
        }]
    }
}
```

{% endtab %}
{% endtabs %}

## CGP History

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/cgp/history`

Get the history of the CGP up to the previous interval

{% tabs %}
{% tab title="200 " %}

```
[...
{
    "interval": 2389,
    "allocation": 89,
    "payout": {}
}, {
    "interval": 2390,
    "allocation": 89,
    "payout": {}
}]
```

{% endtab %}
{% endtabs %}

## CGP Info

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/contract/cgp`

Provide info on how to execute the cgp contract

{% tabs %}
{% tab title="200 " %}

```
{
    "raw": {
        "dict": [
            [
                "Outputs",
                {
                    "list": [
                        {
                            "list": [
                                {
                                    "lock": {
                                        "PK": {
                                            "hash": "f2677af8c95b86a104cb09b214bd4af9794b3edc876fdc2f13794acff366250f",
                                            "address": "tzn1q7fnh47xftwr2zpxtpxepf022l9u5k0kusahactcn099vlumxy58s4kzzx6"
                                        }
                                    }
                                },
                                {
                                    "list": [
                                        {
                                            "string": "000000000000000000000000000000000000000000000000000000000000000000000000"
                                        },
                                        {
                                            "u64": 12300000000
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        ]
    },
    "encoded": "0c01074f7574707574730d010d02080220f2677af8c95b86a104cb09b214bd4af9794b3edc876fdc2f13794acff366250f0d0206483030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030300500000002dd231b00000000",
    "cgpContract": "00000000eac6c58bed912ff310df9f6960e8ed5c28aac83b8a98964224bab1e06c779b93"
}
```

{% endtab %}
{% endtabs %}

## Total ZP

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/totalzp`

Get the total minted ZP up to a precise block

#### Path Parameters

| Name        | Type   | Description |
| ----------- | ------ | ----------- |
| blockNumber | string |             |

{% tabs %}
{% tab title="200 " %}

```
236520
```

{% endtab %}
{% endtabs %}

## Block headers

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/headers`

Returns a list of some information about each header on the main chain in JSON format

#### Query Parameters

| Name        | Type   | Description                                            |
| ----------- | ------ | ------------------------------------------------------ |
| blockNumber | string | start to take from blockNumber. Must be used with take |
| take        | string | take the first n blocks instead of all of the headers  |

{% tabs %}
{% tab title="200 " %}

```javascript
[{
        "hash": "hash"
        "timestamp": timestamp,
        "date": "19-07-21 11:16:17",
        "blockNumber": 1,
        "difficulty": "difficulty",
        "target": "target"
}...]
```

{% endtab %}
{% endtabs %}

## Blockchain Info

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/info`

Returns information about the current status of the blockchain

{% tabs %}
{% tab title="200 " %}

```
{
    "chain": "testnet",
    "blocks": "blocks",
    "headers": "headers",
    "difficulty": "difficulty",
    "medianTime": "medianTime",
    "initialBlockDownload": false,
    "tip": "tip"
}
```

{% endtab %}
{% endtabs %}

## Block

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/block`

Return the content of a block by providing either the block number or the hash of the block&#x20;

#### Path Parameters

| Name        | Type   | Description         |
| ----------- | ------ | ------------------- |
| blockNumber | string | block number wanted |
| hash        | string | hash of block       |

{% tabs %}
{% tab title="200 " %}

```json
{
    "hash": "0000000000134025e160d8bc9e2aa4679922577d6c4a19e913e794d9553fc7b1",
    "header": {
        "version": 0,
        "parent": "000000000005f82adc623950001be45869a55a9f6547988f691352bc3e569d21",
        "blockNumber": 173,
        "commitments": "a81f0356128748f3b32f75bb81b204efc326d29e200f8b02bcd30dcd0f2e8011",
        "timestamp": 1530385197246,
        "difficulty": 455897445,
        "nonce": [
            450089378218827185,
            -5391090228939172857
        ]
    },
    "transactions": {
        "6a8e563d53a1dcdf7eb8827a1643d7d9edf1af4665c50146f24d648578469a8d": {
            "version": 0,
            "inputs": [],
            "outputs": [
                {
                    "lock": {
                        "Coinbase": {
                            "blockNumber": 173,
                            "pkHash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                            "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc"
                        }
                    },
                    "spend": {
                        "asset": "00",
                        "amount": "5000000000"
                    }
                }
            ],
            "witness": []
        },
        "89d60fdaab712639b38159b95503e20c1d93d71be547098233c89167de8ef033": {
            "version": 0,
            "inputs": [
                ...,
                {
                    "outpoint": {
                        "txHash": "a7934d6f8d88c120e2b65350889767ab1c2b075b0e4c596de4ef410e33a6d454",
                        "index": 0
                    }
                }
            ],
            "outputs": [
                {
                    "lock": {
                        "PK": {
                            "hash": "3ef74862aad449d4e509cdcdf6131f9f462ada5d0f999992855a6eba04ac3860",
                            "address": "zen1q8mm5sc4263yafegfehxlvyclnarz4kjap7veny59tfht5p9v8psqdzng5l"
                        }
                    },
                    "spend": {
                        "asset": "00",
                        "amount": "100000000000"
                    }
                }
            ],
            "witness": [
                ...,
                {
                    "PKWitness": {
                        "sigHash": "txHash",
                        "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                        "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                        "signature": "cdbf797eb5d4da7f4e4ab7c4ad02435d86a6548341ceab827ebf0354dbd734363ca0180df6dbf8623ec963bd054d07a7803e3f190655855c3ecded890cb23560"
                    }
                }
            ]
        }
    }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```
hash or blockNumber are missing
```

{% endtab %}
{% endtabs %}

## Block Reward

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/blockreward`

Return the reward at a given block

#### Path Parameters

| Name                                          | Type   | Description              |
| --------------------------------------------- | ------ | ------------------------ |
| blockNumber<mark style="color:red;">\*</mark> | string | Number of block to check |

{% tabs %}
{% tab title="200 " %}

```
5000000000

```

{% endtab %}

{% tab title="400: Bad Request " %}

```
blockNumber is missing
```

{% endtab %}
{% endtabs %}

## Get Transaction

<mark style="color:blue;">`GET`</mark> `http://127.0.0.1:31567/blockchain/transaction`

Return the data of the provided transaction

#### Query Parameters

| Name                                   | Type   | Description                             |
| -------------------------------------- | ------ | --------------------------------------- |
| hash<mark style="color:red;">\*</mark> | string | Hash of a transaction                   |
| hex                                    | string | if true it returns the tx in hex format |

{% tabs %}
{% tab title="200 " %}

```json
{
    "tx": {
        "version": 0,
        "inputs": [
            {
                "outpoint": {
                    "txHash": "a880d71f4711d329d8de232a6ca762bd1a921f8bcc5cbbe5c951410271cd7487",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "af95d752102168833c17d5b811fe8d29b95bc362c795cfe4c369651f18536947",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "b1e957ca66a35496c2e1ab452dc214d727b14786734644b9bee935795ceb562f",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "b8bc6169206fd11b8c49885e1f344d6ebbc57257b542b11cfc9ab99faefefce3",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "be137110b99d6c73cd96b2b3b2b5d799140bd5d435e178aa7e50b692f4ac6571",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "c0cbea76ee2051a5cfa173e483da630275f5594ea2223fbfc20359ea27d10e88",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "d6c23a31aab8d523d53b0ae291a818b7c22382212b2d49c53008a65449e389cd",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "d8326a8e17bc4f3a01310755b921d22f3d6828007e514368c3d6fb82f373008b",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "e953b9b14e4620e12dbaeb3a12a99452ae936d86a0d89bcb7b2f995924adfff5",
                    "index": 0
                }
            },
            {
                "outpoint": {
                    "txHash": "efb796ba6d8ff18ff0ad5a70a1591b4ca30ffbf917bf9a44d6e7954092749d94",
                    "index": 0
                }
            }
        ],
        "outputs": [
            {
                "lock": {
                    "PK": {
                        "hash": "3ef74862aad449d4e509cdcdf6131f9f462ada5d0f999992855a6eba04ac3860",
                        "address": "zen1q8mm5sc4263yafegfehxlvyclnarz4kjap7veny59tfht5p9v8psqdzng5l"
                    }
                },
                "spend": {
                    "asset": "00",
                    "amount": "50000000000"
                }
            }
        ],
        "witness": [
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            },
            {
                "PKWitness": {
                    "sigHash": "txHash",
                    "hash": "72c9f711659f19759967607f305da968f77f49e67ff23488d36fbd4df6a07b57",
                    "address": "zen1qwtylwyt9nuvhtxt8vplnqhdfdrmh7j0x0lerfzxnd775ma4q0dtscc2tjc",
                    "signature": "8e8b0295b2f6407812d8de1853200ceab5c218f8626cb0d32b2fc655f25ce78b61b82f811ab7e602082d3ed21171c5c6a5f5ebd97d080114e27b443a292fc03e"
                }
            }
        ]
    },
    "confirmations": 640787
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```
transaction not found
```

{% endtab %}
{% endtabs %}

## Publish Block

<mark style="color:green;">`POST`</mark> `http://127.0.0.1:31567/blockchain/publishblock`

Publish a block only provide block in hex format or header and body

#### Request Body

| Name   | Type   | Description   |
| ------ | ------ | ------------- |
| body   | string | in hex format |
| header | string | in hex format |
| block  | string | in hex format |

{% tabs %}
{% tab title="200 " %}

```
000000000008bf918c4672a4b5b7a4928cf180adefab696947de56c948240e47
```

{% endtab %}

{% tab title="400 error" %}

```
proof of work failed
```

{% endtab %}
{% endtabs %}

## Submit Header

<mark style="color:green;">`POST`</mark> `http://127.0.0.1:31567/blockchain/submitheader`

Submit hex formatted header to add the block

#### Request Body

| Name   | Type   | Description          |
| ------ | ------ | -------------------- |
| header | string | The header to submit |

{% tabs %}
{% tab title="200 " %}

```
cb746bfdbc472602064dbc04e66326a8edf11a3c64d08ddfa90257e86e866b0f
```

{% endtab %}
{% endtabs %}

## Block Template

<mark style="color:green;">`POST`</mark> `http://127.0.0.1:31567/blockchain/blocktemplate`

Request a block template to add on top the mempool transaction

#### Path Parameters

| Name    | Type   | Description            |
| ------- | ------ | ---------------------- |
| address | string | Miner coinbase address |

{% tabs %}
{% tab title="200 " %}

```json
{
    "header": "000000010000000004357e167370845a22b741b01cfc392a3d0cafa5736042ea13910a8c000085c82deddef70ebc9a16f150047ad0fe9118b46b6099c2b89c4bef0d09a1e620c575000001884358696e1c0582dd00000000000000000000000000000000",
    "body": "039bf2e442f34d15fd09d2a6a6cf97e9d65758a39a4a1cba8b76102e15e81a7ec334e357f5efa4b6cdaf25a1c51f4ab17769ab29594d318e45b6fa9281f8c60516f7e92b9cb5a9e696a0d7cfc1f00e974ce2c1693b63a5e647a00f545dbd996818010000000000010624000085c8f2677af8c95b86a104cb09b214bd4af9794b3edc876fdc2f13794acff366250f007e0000012a0603760000",
    "target": "000000000582dd00000000000000000000000000000000000000000000000000",
    "parent": "0000000004357e167370845a22b741b01cfc392a3d0cafa5736042ea13910a8c",
    "blockNumber": 34248
}
```

{% endtab %}
{% endtabs %}

## Publish Transaction

<mark style="color:green;">`POST`</mark> `http://127.0.0.1:31567/blockchain/publishtransaction`

Publish an hex encoded transaction into the mempool&#x20;

#### Request Body

| Name                                 | Type   | Description               |
| ------------------------------------ | ------ | ------------------------- |
| tx<mark style="color:red;">\*</mark> | string | transaction in hex format |

{% tabs %}
{% tab title="200 " %}

```
e4592f72c0201345b750fde240309224a7964e2b516440e2bfa0f62d3bc59bb5
```

{% endtab %}

{% tab title="400 " %}

```
invalid transaction
```

{% endtab %}
{% endtabs %}

## Execute Contract

<mark style="color:green;">`POST`</mark> `http://127.0.0.1:31567/blockchain/contract/execute`

Execute a contract by given different data&#x20;

#### Request Body

| Name         | Type   | Description                      |
| ------------ | ------ | -------------------------------- |
| command      | string | command provided to the contract |
| messageBody  | string | message body in hex format       |
| otion.sender | string | bip39 path                       |
| tx           | string | Tx in hex format                 |
| address      | string | Contract Address                 |

{% tabs %}
{% tab title="200 tx in hex format" %}

```
123456789abcdef 
```

{% endtab %}
{% endtabs %}
