# Contract

## 1. Get contract list

```javascript
url：/v2/contracts?page_size=10&page_number=1, 
method：GET, 
successResponse：{
    "code":0, 
    "msg":"SUCCESS", 
    "result":{
        "records":[
            {
                "contract_hash": "16edbe366d...99424c94aeef02", 
                "name": "name", 
                "logo":"", 
                "description": "is a decentralized, tru.....", 
                "creator": "AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM", 
                "create_time":1516946305, 
                "update_time":1516948340, 
                "contact_info":"{\"website\":\"www.test.cn\", \"github\":\"github.com\"}", 
                "ont_sum": "2123", 
                "ong_sum": "1233123123.002", 
                "address_count": 122, 
                "tx_count": 30, 
                "token_sum":{\"Ht\":\"124\"}", 
                "category":"oep", 
                "type":"oep4", 
                "dapp_name":""
            }
        ], 
        "total":12
    }
}
```

| Url RequestField | Type | Description                                                               |
| ---------------- | ---- | ------------------------------------------------------------------------- |
| page\_size       | int  | number of records in one page (The page size is limited between 1 and 20) |
| page\_number     | int  | number of the page (At least 1 or greater)                                |

| Response Parameter | Type   | Description                            |
| ------------------ | ------ | -------------------------------------- |
| contract\_hash     | String | contract hash                          |
| name               | String | contract name                          |
| create\_time       | int    | create time                            |
| update\_time       | int    | update time                            |
| contact\_info      | String | contact information.JSON format string |
| logo               | String | logo url                               |
| description        | String | contract description                   |
| creator            | String | creator address                        |
| ong\_sum           | String | total ong                              |
| ont\_sum           | String | total ont                              |
| address\_count     | int    | total address                          |
| tx\_count          | int    | total transaction                      |
| token\_sum         | String | total token.JSON format string         |
| category           | String | category                               |
| type               | String | oep4, oep5, oep8, other                |
| dapp\_name         | String | dapp name                              |
| total              | int    | total contract                         |

## 2. Get contract detail by contract\_hash

```javascript
url：/v2/contracts/{contract_hash}, 
method：GET, 
successResponse：{
    "code":0, 
    "msg":"SUCCESS", 
    "result":{
        "contract_hash": "16edbe366d...99424c94aeef02", 
        "name": "name", 
        "abi":"25a80bbc...5381", 
        "code": "013ec56b6...006a5", 
        "source_code":"", 
        "create_time":1516946305, 
        "update_time":1516948340, 
        "contact_info":"{\"website\":\"www.test.cn\", \"github\":\"github.com\"}", 
        "logo":"", 
        "description": "LuckyNumber is a decentralized, tru.....", 
        "creator": "AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM", 
        "ont_sum": "2123", 
        "ong_sum": "1233123123", 
        "address_count": 122, 
        "tx_count": 30, 
        "token_sum":{\"Ht\":\"124\"}", 
        "category":"oep", 
        "type":"oep5", 
        "dapp_name":""
    }
}
```

| Response Parameter  | Type    | Description                            |
| ------------------- | ------- | -------------------------------------- |
| contract\_hash      | String  | contract hash                          |
| name                | String  | contract name                          |
| create\_time        | int     | create time                            |
| update\_time        | int     | update time                            |
| contact\_info       | String  | contact information.JSON format string |
| logo                | String  | logo url                               |
| description         | String  | contract description                   |
| creator             | String  | creator address                        |
| ong\_sum            | String  | total ong                              |
| ont\_sum            | String  | total ont                              |
| address\_count      | int     | total address                          |
| tx\_count           | int     | total transaction                      |
| token\_sum          | String  | total token.JSON format string         |
| type                | String  | oep4, oep5, oep8, others               |
| abi                 | String  | contract abi                           |
| code                | String  | contract code                          |
| source\_code        | String  | contract source code                   |
| category            | String  | category                               |
| dapp\_name          | String  | dapp name                              |
| vm\_type            | String  | VM type                                |
| compiler\_type      | String  | compiler type                          |
| compiler\_version   | String  | compiler version                       |
| optimization        | boolean | whether to optimize                    |
| optimization\_run   | int     | optimization steps                     |
| vm\_version         | String  | EVM version                            |
| licenseType         | String  | license type                           |
| constructorArgument | String  | constructor arguments                  |
| setting             | String  | setting                                |

## 3. Get contract transaction list by contracthash

```javascript
url：/v2/contracts/{contract_type}/{contract_hash}/transactions?page_size=10&page_number=1, 
method：GET, 
successResponse：{
    "code":0, 
    "msg":"SUCCESS", 
    "result":{
    	"records":[
    		{
                "tx_hash":"9762458cd30612509f7c...a010ccc7b347057eb5", 
                "tx_type":209, 
                "tx_time":1522210288, 
                "block_height":1212, 
                "confirm_flag":1, 
                "block_index":1, 
                "fee":"0.01"
    		}
    	], 
    	"total":20
    }
}
```

| Url RequestField | Type   | Description                                                               |
| ---------------- | ------ | ------------------------------------------------------------------------- |
| page\_size       | int    | number of records in one page (The page size is limited between 1 and 20) |
| page\_number     | int    | number of the page (At least 1 or greater)                                |
| contract\_type   | String | oep4, oep5, oep8, other                                                   |
| contract\_hash   | String | contract\_hash                                                            |

| ResponseField         | Type   | Description                                              |
| --------------------- | ------ | -------------------------------------------------------- |
| records.tx\_hash      | String | transaction hash                                         |
| records.tx\_type      | int    | transaction type (208/209/210)                           |
| records.tx\_time      | int    | UNIX time of the transaction                             |
| records.block\_height | int    | block height                                             |
| records.confirm\_flag | int    | transaction state on the blockchain, 0:failure 1:success |
| records.block\_index  | int    | The index of transactions within a block                 |
| txs.fee               | String | fee                                                      |
| total                 | int    | total                                                    |

### **HyperDragon OEP5 Contract**

Response two more parameters：

* asset\_name：asset name
* json\_url：json data

```javascript
successResponse：{
    "code":0, 
    "msg":"SUCCESS", 
    "result":{
    	"txs":[
    		{
                "tx_hash":"9762458cd30612509f7c...a010ccc7b347057eb5", 
                "tx_type":209, 
                "tx_time":1522210288, 
                "block_height":1212, 
                "confirm_flag":1, 
                "block_index":1, 
                "fee":"0.01", 
                "asset_name":"HyperDragons: 1360", 
                "json_url":"{\"image\":\"https://hyd-go-res.alfakingdom.com/normal/1360.svg\", \"name\":\"dragon#1360\"}"   //如果asset_name没有找到对应的json描述，该字段不返回
    		}
    	], 
    	"total":20
    }
}
```

## 4. Get contract transaction list by contracthash

```javascript
url：/v2/contracts/{contract_hash}/transactions?page_size=10&page_number=1, 
method：GET, 
successResponse：{
    "code":0, 
    "msg":"SUCCESS", 
    "result":{
    	"records":[
    		{
                "tx_hash":"9762458cd30612509f7c...a010ccc7b347057eb5", 
                "tx_type":209, 
                "tx_time":1522210288, 
                "block_height":1212, 
                "confirm_flag":1, 
                "block_index":1, 
                "fee":"0.01"
    		}
    	], 
    	"total":20
    }
}
```

| Url RequestField | Type   | Description                                                               |
| ---------------- | ------ | ------------------------------------------------------------------------- |
| page\_size       | int    | number of records in one page (The page size is limited between 1 and 20) |
| page\_number     | int    | number of the page (At least 1 or greater)                                |
| contract\_type   | String | oep4, oep5, oep8, other                                                   |
| contract\_hash   | String | contract\_hash                                                            |

| ResponseField         | Type   | Description                                              |
| --------------------- | ------ | -------------------------------------------------------- |
| records.tx\_hash      | String | transaction hash                                         |
| records.tx\_type      | int    | transaction type (208/209/210)                           |
| records.tx\_time      | int    | UNIX time of the transaction                             |
| records.block\_height | int    | block height                                             |
| records.confirm\_flag | int    | transaction state on the blockchain, 0:failure 1:success |
| records.block\_index  | int    | The index of transactions within a block                 |
| txs.fee               | String | fee                                                      |
| total                 | int    | total                                                    |

### **Hyperdragon OEP5 Contract**

Two extra fields in response:

* asset\_name：Name of the asset
* json\_url: JSON string of the dragon logo and name. If the `asset_name` doesn't have a corresponding JSON description, this field will not be returned

```javascript
successResponse：{
    "code":0, 
    "msg":"SUCCESS", 
    "result":{
    	"txs":[
    		{
                "tx_hash":"9762458cd30612509f7c...a010ccc7b347057eb5", 
                "tx_type":209, 
                "tx_time":1522210288, 
                "block_height":1212, 
                "confirm_flag":1, 
                "block_index":1, 
                "fee":"0.01", 
                "asset_name":"HyperDragons: 1360", 
                "json_url":"{\"image\":\"https://hyd-go-res.alfakingdom.com/normal/1360.svg\", \"name\":\"dragon#1360\"}"   //If the `asset_name` doesn't have a corresponding JSON description, this field will not be returned
    		}
    	], 
    	"total":20
    }
}
```
