|
| 1 | +# API Reference |
| 2 | + |
| 3 | +The PHPcoin API provides a set of endpoints for interacting with the blockchain. The API is accessible via HTTP and returns data in JSON format. |
| 4 | + |
| 5 | +## Accounts |
| 6 | + |
| 7 | +### getAddress |
| 8 | + |
| 9 | +Converts a public key to a PHPcoin address. |
| 10 | + |
| 11 | +* **URL:** `/api.php?q=getAddress` |
| 12 | +* **Method:** `GET` |
| 13 | +* **Parameters:** |
| 14 | + * `public_key` (string, required): The public key to convert. |
| 15 | +* **Example:** |
| 16 | + ``` |
| 17 | + /api.php?q=getAddress&public_key=... |
| 18 | + ``` |
| 19 | +
|
| 20 | +### getBalance |
| 21 | +
|
| 22 | +Returns the balance of a specific address. |
| 23 | +
|
| 24 | +* **URL:** `/api.php?q=getBalance` |
| 25 | +* **Method:** `GET` |
| 26 | +* **Parameters:** |
| 27 | + * `address` (string, required): The address to check. |
| 28 | +* **Example:** |
| 29 | + ``` |
| 30 | + /api.php?q=getBalance&address=... |
| 31 | + ``` |
| 32 | +
|
| 33 | +### getPendingBalance |
| 34 | +
|
| 35 | +Returns the pending balance of a specific address, which includes unconfirmed transactions. |
| 36 | +
|
| 37 | +* **URL:** `/api.php?q=getPendingBalance` |
| 38 | +* **Method:** `GET` |
| 39 | +* **Parameters:** |
| 40 | + * `address` (string, required): The address to check. |
| 41 | +* **Example:** |
| 42 | + ``` |
| 43 | + /api.php?q=getPendingBalance&address=... |
| 44 | + ``` |
| 45 | +
|
| 46 | +### getPublicKey |
| 47 | +
|
| 48 | +Returns the public key of a specific address. |
| 49 | +
|
| 50 | +* **URL:** `/api.php?q=getPublicKey` |
| 51 | +* **Method:** `GET` |
| 52 | +* **Parameters:** |
| 53 | + * `address` (string, required): The address to check. |
| 54 | +* **Example:** |
| 55 | + ``` |
| 56 | + /api.php?q=getPublicKey&address=... |
| 57 | + ``` |
| 58 | +
|
| 59 | +### generateAccount |
| 60 | +
|
| 61 | +Generates a new PHPcoin account. |
| 62 | +
|
| 63 | +* **URL:** `/api.php?q=generateAccount` |
| 64 | +* **Method:** `GET` |
| 65 | +* **Example:** |
| 66 | + ``` |
| 67 | + /api.php?q=generateAccount |
| 68 | + ``` |
| 69 | +
|
| 70 | +## Transactions |
| 71 | +
|
| 72 | +### getTransactions |
| 73 | +
|
| 74 | +Returns the latest transactions for a specific address. |
| 75 | +
|
| 76 | +* **URL:** `/api.php?q=getTransactions` |
| 77 | +* **Method:** `GET` |
| 78 | +* **Parameters:** |
| 79 | + * `address` (string, required): The address to check. |
| 80 | + * `limit` (integer, optional): The maximum number of transactions to return. |
| 81 | + * `offset` (integer, optional): The offset to start from. |
| 82 | +* **Example:** |
| 83 | + ``` |
| 84 | + /api.php?q=getTransactions&address=...&limit=10 |
| 85 | + ``` |
| 86 | +
|
| 87 | +### getTransaction |
| 88 | +
|
| 89 | +Returns a specific transaction by its ID. |
| 90 | +
|
| 91 | +* **URL:** `/api.php?q=getTransaction` |
| 92 | +* **Method:** `GET` |
| 93 | +* **Parameters:** |
| 94 | + * `transaction` (string, required): The ID of the transaction. |
| 95 | +* **Example:** |
| 96 | + ``` |
| 97 | + /api.php?q=getTransaction&transaction=... |
| 98 | + ``` |
| 99 | +
|
| 100 | +### send |
| 101 | +
|
| 102 | +Sends a transaction to the network. |
| 103 | +
|
| 104 | +* **URL:** `/api.php?q=send` |
| 105 | +* **Method:** `POST` |
| 106 | +* **Parameters:** |
| 107 | + * `val` (float, required): The amount to send. |
| 108 | + * `dst` (string, required): The destination address. |
| 109 | + * `public_key` (string, required): The sender's public key. |
| 110 | + * `signature` (string, required): The transaction signature. |
| 111 | + * `date` (integer, required): The transaction date (Unix timestamp). |
| 112 | + * `message` (string, optional): A message to include with the transaction. |
| 113 | +* **Example:** |
| 114 | + ```json |
| 115 | + { |
| 116 | + "val": 10.0, |
| 117 | + "dst": "...", |
| 118 | + "public_key": "...", |
| 119 | + "signature": "...", |
| 120 | + "date": 1678886400, |
| 121 | + "message": "Hello, world!" |
| 122 | + } |
| 123 | + ``` |
| 124 | +
|
| 125 | +## Blocks |
| 126 | +
|
| 127 | +### currentBlock |
| 128 | +
|
| 129 | +Returns the current block. |
| 130 | +
|
| 131 | +* **URL:** `/api.php?q=currentBlock` |
| 132 | +* **Method:** `GET` |
| 133 | +* **Example:** |
| 134 | + ``` |
| 135 | + /api.php?q=currentBlock |
| 136 | + ``` |
| 137 | +
|
| 138 | +### getBlock |
| 139 | +
|
| 140 | +Returns a specific block by its height. |
| 141 | +
|
| 142 | +* **URL:** `/api.php?q=getBlock` |
| 143 | +* **Method:** `GET` |
| 144 | +* **Parameters:** |
| 145 | + * `height` (integer, required): The height of the block. |
| 146 | +* **Example:** |
| 147 | + ``` |
| 148 | + /api.php?q=getBlock&height=12345 |
| 149 | + ``` |
| 150 | +
|
| 151 | +### getBlockTransactions |
| 152 | +
|
| 153 | +Returns the transactions of a specific block. |
| 154 | +
|
| 155 | +* **URL:** `/api.php?q=getBlockTransactions` |
| 156 | +* **Method:** `GET` |
| 157 | +* **Parameters:** |
| 158 | + * `height` (integer, required): The height of the block. |
| 159 | +* **Example:** |
| 160 | + ``` |
| 161 | + /api.php?q=getBlockTransactions&height=12345 |
| 162 | + ``` |
| 163 | +
|
| 164 | +## Node |
| 165 | +
|
| 166 | +### version |
| 167 | +
|
| 168 | +Returns the version of the node. |
| 169 | +
|
| 170 | +* **URL:** `/api.php?q=version` |
| 171 | +* **Method:** `GET` |
| 172 | +* **Example:** |
| 173 | + ``` |
| 174 | + /api.php?q=version |
| 175 | + ``` |
| 176 | +
|
| 177 | +### mempoolSize |
| 178 | +
|
| 179 | +Returns the number of transactions in the mempool. |
| 180 | +
|
| 181 | +* **URL:** `/api.php?q=mempoolSize` |
| 182 | +* **Method:** `GET` |
| 183 | +* **Example:** |
| 184 | + ``` |
| 185 | + /api.php?q=mempoolSize |
| 186 | + ``` |
| 187 | +
|
| 188 | +### nodeInfo |
| 189 | +
|
| 190 | +Returns information about the node. |
| 191 | +
|
| 192 | +* **URL:** `/api.php?q=nodeInfo` |
| 193 | +* **Method:** `GET` |
| 194 | +* **Example:** |
| 195 | + ``` |
| 196 | + /api.php?q=nodeInfo |
| 197 | + ``` |
| 198 | +
|
| 199 | +### getPeers |
| 200 | +
|
| 201 | +Returns a list of the node's peers. |
| 202 | +
|
| 203 | +* **URL:** `/api.php?q=getPeers` |
| 204 | +* **Method:** `GET` |
| 205 | +* **Example:** |
| 206 | + ``` |
| 207 | + /api.php?q=getPeers |
| 208 | + ``` |
| 209 | +
|
| 210 | +## Masternodes |
| 211 | +
|
| 212 | +### getMasternodes |
| 213 | +
|
| 214 | +Returns a list of all masternodes. |
| 215 | +
|
| 216 | +* **URL:** `/api.php?q=getMasternodes` |
| 217 | +* **Method:** `GET` |
| 218 | +* **Example:** |
| 219 | + ``` |
| 220 | + /api.php?q=getMasternodes |
| 221 | + ``` |
| 222 | +
|
| 223 | +### getMasternode |
| 224 | +
|
| 225 | +Returns a specific masternode by its address. |
| 226 | +
|
| 227 | +* **URL:** `/api.php?q=getMasternode` |
| 228 | +* **Method:** `GET` |
| 229 | +* **Parameters:** |
| 230 | + * `address` (string, required): The address of the masternode. |
| 231 | +* **Example:** |
| 232 | + ``` |
| 233 | + /api.php?q=getMasternode&address=... |
| 234 | + ``` |
| 235 | +
|
| 236 | +## Smart Contracts |
| 237 | +
|
| 238 | +### getSmartContract |
| 239 | +
|
| 240 | +Returns a specific smart contract by its address. |
| 241 | +
|
| 242 | +* **URL:** `/api.php?q=getSmartContract` |
| 243 | +* **Method:** `GET` |
| 244 | +* **Parameters:** |
| 245 | + * `address` (string, required): The address of the smart contract. |
| 246 | +* **Example:** |
| 247 | + ``` |
| 248 | + /api.php?q=getSmartContract&address=... |
| 249 | + ``` |
| 250 | +
|
| 251 | +### getSmartContractProperty |
| 252 | +
|
| 253 | +Reads a property of a smart contract. |
| 254 | +
|
| 255 | +* **URL:** `/api.php?q=getSmartContractProperty` |
| 256 | +* **Method:** `GET` |
| 257 | +* **Parameters:** |
| 258 | + * `address` (string, required): The address of the smart contract. |
| 259 | + * `property` (string, required): The name of the property to read. |
| 260 | + * `key` (string, optional): The key of the property, if it's a map. |
| 261 | +* **Example:** |
| 262 | + ``` |
| 263 | + /api.php?q=getSmartContractProperty&address=...&property=myProperty&key=myKey |
| 264 | + ``` |
| 265 | +
|
| 266 | +### getSmartContractInterface |
| 267 | +
|
| 268 | +Returns the interface of a smart contract. |
| 269 | +
|
| 270 | +* **URL:** `/api.php?q=getSmartContractInterface` |
| 271 | +* **Method:** `GET` |
| 272 | +* **Parameters:** |
| 273 | + * `address` (string, required): The address of the smart contract. |
| 274 | +* **Example:** |
| 275 | + ``` |
| 276 | + /api.php?q=getSmartContractInterface&address=... |
| 277 | + ``` |
| 278 | +
|
| 279 | +### getSmartContractView |
| 280 | +
|
| 281 | +Executes a view method of a smart contract. |
| 282 | +
|
| 283 | +* **URL:** `/api.php?q=getSmartContractView` |
| 284 | +* **Method:** `GET` |
| 285 | +* **Parameters:** |
| 286 | + * `address` (string, required): The address of the smart contract. |
| 287 | + * `method` (string, required): The name of the view method to execute. |
| 288 | + * `params` (string, optional): The parameters for the method, as a base64-encoded JSON string. |
| 289 | +* **Example:** |
| 290 | + ``` |
| 291 | + /api.php?q=getSmartContractView&address=...&method=myMethod¶ms=... |
| 292 | + ``` |
0 commit comments