github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/doc/API.md (about) 1 Siad API 2 ======== 3 4 The siad API is currently under construction. Under semantic versioning, the 5 minor version will be incremented whenever API-breaking changes are introduced. 6 Once siad hits v1.0.0, the major version will be incremented instead. 7 8 All API calls return JSON objects. If there is an error, the error is returned 9 in plaintext with an appropriate HTTP error code. The standard response is { 10 "Success": true }. In this document, the API responses are defined as Go 11 structs. The structs will be encoded to JSON before being sent; they are used 12 here to provide type information. 13 14 There may be functional API calls which are not documented. These are not 15 guaranteed to be supported beyond the current release, and should not be used 16 in production. 17 18 Notes: 19 - Requests must set their User-Agent string to contain the substring "Sia-Agent". 20 - By default, siad listens on "localhost:9980". This can be changed using the 21 '--api-addr' flag when running siad. 22 - The types.Currency object is an arbitrary-precision unsigned integer. In JSON, 23 it is represented as a base-10 string. You must use a "bignum" library to handle 24 these values, or you risk losing precision. 25 26 Example GET curl call: `curl -A "Sia-Agent" /wallet/transactions?startheight=1&endheight=250` 27 28 Example POST curl call: `curl -A "Sia-Agent" --data "amount=123&destination=abcd" /wallet/siacoins 29 30 Daemon 31 ------ 32 33 Queries: 34 35 * /daemon/constants [GET] 36 * /daemon/stop [GET] 37 * /daemon/version [GET] 38 39 #### /daemon/constants [GET] 40 41 Function: Returns the set of constants in use. 42 43 Parameters: none 44 45 Response: 46 ``` 47 struct { 48 genesistimestamp types.Timestamp (uint64) 49 blocksizelimit uint64 50 blockfrequency types.BlockHeight (uint64) 51 targetwindow types.BlockHeight (uint64) 52 mediantimestampwindow uint64 53 futurethreshold types.Timestamp (uint64) 54 siafundcount types.Currency (string) 55 siafundportion *big.Rat (string) 56 maturitydelay types.BlockHeight (uint64) 57 58 initialcoinbase uint64 59 minimumcoinbase uint64 60 61 roottarget types.Target (byte array) 62 rootdepth types.Target (byte array) 63 64 maxadjustmentup *big.Rat (string) 65 maxadjustmentdown *big.Rat (string) 66 67 siacoinprecision types.Currency (string) 68 } 69 ``` 70 'genesistimestamp' is the timestamp of the genesis block. 71 72 'blocksizelimit' is the maximum size a block can be without being rejected. 73 74 'blockfrequency' is the target for how frequently new blocks should be mined. 75 76 'targetwindow' is the height of the window used to adjust the difficulty. 77 78 'mediantimestampwindow' is the duration of the window used to adjust the 79 difficulty. 80 81 'futurethreshold' is how far in the future a block can be without being 82 rejected. 83 84 'siafundcount' is the total number of siafunds. 85 86 'siafundportion' is the percentage of each file contract payout given to 87 siafund holders. 88 89 'maturitydelay' is the number of children a block must have before it is 90 considered "mature." 91 92 'initialcoinbase' is the number of coins given to the miner of the first 93 block. 94 95 'minimumcoinbase' is the minimum number of coins paid out to the miner of a 96 block (the coinbase decreases with each block). 97 98 'roottarget' is the initial target. 99 100 'rootdepth' is the initial depth. 101 102 'maxadjustmentup' is the largest allowed ratio between the old difficulty and 103 the new difficulty. 104 105 'maxadjustmentdown' is the smallest allowed ratio between the old difficulty 106 and the new difficulty. 107 108 'siacoinprecision' is the number of Hastings in one siacoin. 109 110 #### /daemon/stop [GET] 111 112 Function: Cleanly shuts down the daemon. May take a few seconds. 113 114 Parameters: none 115 116 Response: standard 117 118 #### /daemon/version [GET] 119 120 Function: Returns the version of Sia currently running. 121 122 Parameters: none 123 124 Response: 125 ``` 126 struct { 127 version string 128 } 129 ``` 130 'version' is the version of the responding Sia daemon. 131 132 Consensus 133 --------- 134 135 Queries: 136 137 * /consensus [GET] 138 139 #### /consensus [GET] 140 141 Function: Returns information about the consensus set, such as the current 142 block height. 143 144 Parameters: none 145 146 Response: 147 ``` 148 struct { 149 synced types.BlockHeight (bool) 150 height types.BlockHeight (uint64) 151 currentblock types.BlockID (string) 152 target types.Target (byte array) 153 } 154 ``` 155 'synced' is a bool that indicates if the consensus set is synced with the 156 network. Will be false during initial blockchain download and true after. 157 158 'height' is the number of blocks in the blockchain. 159 160 'currentblock' is the hash of the current block. 161 162 'target' is the hash that needs to be met by a block for the block to be valid. 163 The target is inversely proportional to the difficulty. 164 165 Explorer 166 -------- 167 168 Queries: 169 170 * /explorer [GET] 171 * /explorer/blocks/{height} [GET] 172 * /explorer/hashes/{hash} [GET] 173 174 #### /explorer [GET] 175 176 Function: Returns the status of the blockchain and some 177 statistics. All Siacoin amounts are given in Hastings 178 179 Parameters: None 180 181 Response: 182 ``` 183 struct { 184 height types.BlockHeight (uint64) 185 block types.Block 186 target types.Target (byte array) 187 difficulty types.Currency (string) 188 maturitytimestamp types.Timestamp (uint64) 189 circulation types.Currency (string) 190 191 transactioncount uint64 192 siacoininputcount uint64 193 siacoinoutputcount uint64 194 filecontractcount uint64 195 filecontractrevisioncount uint64 196 storageproofcount uint64 197 siafundinputcount uint64 198 siafundoutputcount uint64 199 minerfeecount uint64 200 arbitrarydatacount uint64 201 transactionsignaturecount uint64 202 203 activecontractcount uint64 204 activecontractcost types.Currency (string) 205 activecontractsize types.Currency (string) 206 totalcontractcost types.Currency (string) 207 totalcontractsize types.Currency (string) 208 } 209 ``` 210 211 #### /explorer/blocks/{height} [GET] 212 213 Function: Returns a block at a given height. 214 215 Parameters: 216 ``` 217 height types.BlockHeight (uint64) 218 ``` 219 'height' is the height of the block that is being requested. The genesis block 220 is at height 0, its child is at height 1, etc. 221 222 Response: 223 ``` 224 struct { 225 block api.ExplorerBlock 226 } 227 ``` 228 229 #### /explorer/hashes/{hash} [GET] 230 231 Function: Returns information about an unknown hash. 232 233 Parameters: 234 ``` 235 hash crypto.Hash (string) 236 ``` 237 'hash' can be an unlock hash, a wallet address, a block ID, a transaction 238 ID, siacoin output ID, file contract ID, siafund output ID, or any of the 239 derivatives of siacoin output IDs (such as miner payout IDs and file contract 240 payout IDs). 241 242 Response: 243 ``` 244 struct { 245 hashtype string 246 block api.ExplorerBlock 247 blocks []api.ExplorerBlock 248 transaction api.ExplorerTransaction 249 transactions []api.ExplorerTransaction 250 } 251 ``` 252 'hashtype' indicates what type of hash was supplied. The options are 'blockid', 253 'transactionid', 'unlockhash', 'siacoinoutputid', 'filecontractid', 254 'siafundoutputid'. If the object is a block, only the 'block' field will be 255 filled out. If the object is a transaction, only the 'transaction' field will 256 be filled out. For all other types, the 'blocks' and 'transactions' fields will 257 be filled out, returning all of the blocks and transactions that feature the 258 provided hash. 259 260 261 Gateway 262 ------- 263 264 Queries: 265 266 * /gateway [GET] 267 * /gateway/add/{netaddress} [POST] 268 * /gateway/remove/{netaddress} [POST] 269 270 #### /gateway 271 272 Function: Returns information about the gateway, including the list of peers. 273 274 Parameters: none 275 276 Response: 277 ``` 278 struct { 279 netaddress string 280 peers []struct { 281 netaddress string 282 version string 283 inbound bool 284 } 285 } 286 ``` 287 'netaddress' is the network address of the Gateway, including its external IP 288 address and the port Sia is listening on. 289 290 'peers' is a list of the network addresses and versions of peers that the 291 Gateway is currently connected to. 292 293 #### /gateway/add/{netaddress} [POST] 294 295 Function: Adds a peer to the gateway. 296 297 Parameters: 298 ``` 299 netaddress string 300 ``` 301 'netaddress' should be a reachable hostname + port number, typically of the 302 form "a.b.c.d:xxxx". 303 304 Response: standard 305 306 #### /gateway/remove/{netaddress} [POST] 307 308 Function: Will remove a peer from the gateway. 309 310 Parameters: 311 ``` 312 netaddress string 313 ``` 314 'netaddress' should be a reachable hostname + port number, typically of the 315 form "a.b.c.d:xxxx". 316 317 Response: standard 318 319 Host 320 ---- 321 322 Queries: 323 324 * /host [GET] 325 * /host [POST] 326 * /host/announce [POST] 327 * /host/delete/{filecontractid} [POST] 328 329 #### /host [GET] 330 331 Function: Fetches status information about the host. 332 333 Parameters: none 334 335 Response: 336 ``` 337 struct { 338 collateral types.Currency (string) 339 maxduration types.BlockHeight (uint64) 340 minduration types.BlockHeight (uint64) 341 netaddress modules.NetAddress (string) 342 price types.Currency (string) 343 totalstorage int64 344 unlockhash types.UnlockHash (string) 345 windowsize types.BlockHeight (uint64) 346 347 acceptingcontracts bool 348 anticipatedrevenue types.Currency (string) 349 numcontracts uint64 350 revenue types.Currency (string) 351 storageremaining int64 352 353 rpcdownloadcalls uint64 354 rpcerrorcalls uint64 355 rpcrenewcalls uint64 356 rpcrevisecalls uint64 357 rpcsettingscalls uint64 358 rpcunrecognizedcalls uint64 359 rpcuploadcalls uint64 360 } 361 ``` 362 'collateral' is the number of hastings per byte per block that are put up as 363 collateral when making file contracts. 364 365 'maxduration' is the maximum allowed duration of a file contract. 366 367 'minduration' is the minimum allowed duration of a file contract. 368 369 'netaddress' is the network address of the host. 370 371 'price' is the number of hastings per byte per block that the host is charging 372 when making file contracts. 373 374 'totalstorage' is the total amount of storage that has been allocated to the 375 host. 376 377 'unlockhash' is the address that hosting revenues will be sent to. 378 379 'windowsize' is the minimum required window that must be given to the host to 380 prove storage of a file. Due to potential spam attacks, bloat, DDOS, and host 381 downtime, 40 blocks is recommended as an absolute minimum. The current network 382 default is 288 blocks. The current software will break entirely below 20 383 blocks, though in theory something as low as 6 blocks could be safe. 384 385 'acceptingcontracts' indicates whether the host is accepting new file 386 contracts, file contract revisions, and file contract renewals. A host that is 387 not accepting these calls will still accept download requests, and will still 388 submit storage proofs to the network. 389 390 'anticipatedrevenue' is the value of the contracts that have been created but 391 not fulfilled. 392 393 'numcontracts' is the number of active contracts that the host is engaged in. 394 395 'revenue' is the total number of Hastings earned from hosting. 396 397 'storageremaining' is 'totalstorage' minus the number of bytes currently being 398 stored. 399 400 'rpcdownloadcalls' is the number of RPCs to the host that requested a download. 401 402 'rpcerrorcalls' is the number of RPCs to the host that returned errors. 403 404 'rpcrenewcalls' is the number of RPCs to the host that requested a file 405 contract renewal. 406 407 'rpcrevisecalls' is the number of RPCs to the host that requested a file 408 contract revision. 409 410 'rpcsettingscalls' is the number of RPCs to the host that requested the host's 411 settings. 412 413 'rpcunrecognizedcalls' is the number of RPCs to the host that used unrecognized 414 identifiers. 415 416 'rpcuploadcalls' is the number of RPCs to the host that tried to upload a file. 417 418 #### /host [POST] 419 420 Function: Configures hosting parameters. All parameters are optional; 421 unspecified parameters will be left unchanged. 422 423 Parameters: 424 ``` 425 collateral int 426 maxduration int 427 minduration int 428 price int 429 totalstorage int 430 windowsize int 431 ``` 432 'collateral' is the number of hastings per byte per block that are put up as 433 collateral when making file contracts. 434 435 'maxduration' is the maximum allowed duration of a file contract. 436 437 'minduration' is the minimum allowed duration of a file contract. 438 439 'price' is the number of hastings per byte per block that the host is charging 440 when making file contracts. 441 442 'totalstorage' is the total amount of storage that has been allocated to the 443 host. 444 445 'windowsize' is the minimum required window that must be given to the host to 446 prove storage of a file. Due to potential spam attacks, bloat, DDOS, and host 447 downtime, 40 blocks is recommended as an absolute minimum. The current network 448 default is 288 blocks. The current software will break entirely below 20 449 blocks, though in theory something as low as 6 blocks could be safe. 450 451 Response: standard 452 453 #### /host/announce [POST] 454 455 Function: The host will announce itself to the network as a source of storage. 456 Generally only needs to be called once. 457 458 Parameters: 459 ``` 460 netaddress string 461 ``` 462 'netaddress' is an optional parameter that specifies the address to be 463 announced. Supplying this parameters will also override standard connectivity 464 checks. 465 466 Response: standard 467 468 #### /host/delete/{filecontractid} [POST] 469 470 Function: Delete a file contract from the host. This will cause the host to 471 lose the future revenue, and also any collateral that the host had placed on 472 the file. Typically, this is only used in emergency situations where capacity 473 must be freed up, or in situations where legal pressure requires a host to 474 delete a contract. 475 476 Parameters: 477 ``` 478 filecontractid types.UnlockHash (string) 479 ``` 480 481 'filecontractid' is the ID of the file contract that is being deleted. 482 483 Response: standard 484 485 Miner 486 ----- 487 488 Queries: 489 490 * /miner [GET] 491 * /miner/start [GET] 492 * /miner/stop [GET] 493 * /miner/header [GET] 494 * /miner/header [POST] 495 496 #### /miner [GET] 497 498 Function: Return the status of the miner. 499 500 Parameters: none 501 502 Response: 503 ``` 504 struct { 505 blocksmined int 506 cpuhashrate int 507 cpumining bool 508 staleblocksmined int 509 } 510 ``` 511 'cpumining' indicates whether the cpu miner is active or not. 512 513 'cpuhashrate' indicates how fast the cpu is hashing, in hashes per second. 514 515 'blocksmined' indicates how many blocks have been mined, this value is remembered after restarting. 516 517 'staleblocksmined' indicates how many stale blocks have been mined, this value is remembered after restarting. 518 519 #### /miner/start [GET] 520 521 Function: Starts a single threaded cpu miner. Does nothing if the cpu miner is 522 already running. 523 524 Parameters: none 525 526 Response: standard 527 528 #### /miner/stop [GET] 529 530 Function: Stops the cpu miner. Does nothing if the cpu miner is not running. 531 532 Parameters: none 533 534 Response: standard 535 536 #### /miner/header [GET] 537 538 Function: Provide a block header that is ready to be grinded on for work. 539 540 Parameters: none 541 542 Response: 543 ``` 544 []byte 545 ``` 546 The response is a byte array containing a target followed by a block header 547 followed by a block. The target is the first 32 bytes. The block header is the 548 following 80 bytes, and the nonce is bytes 32-39 (inclusive) of the header 549 (bytes 64-71 of the whole array). 550 551 Layout: 552 553 0-31: target 554 555 32-111: header 556 557 #### /miner/header [POST] 558 559 Function: Submit a header that has passed the POW. 560 561 Parameters: 562 ``` 563 input []byte 564 ``` 565 The input byte array should be 80 bytes that form the solved block header. *Unlike most API calls, it should be written directly to the request body, not as a query parameter.* 566 567 Renter 568 ------ 569 570 Queries: 571 572 * /renter/allowance [GET] 573 * /renter/allowance [POST] 574 * /renter/downloads [GET] 575 * /renter/files [GET] 576 * /renter/load [POST] 577 * /renter/loadascii [POST] 578 * /renter/share [GET] 579 * /renter/shareascii [GET] 580 * /renter/delete/{siapath} [POST] 581 * /renter/download/{siapath} [GET] 582 * /renter/rename/{siapath} [POST] 583 * /renter/upload/{siapath} [POST] 584 * /renter/hosts/active [GET] 585 * /renter/hosts/all [GET] 586 587 #### /renter/allowance [GET] 588 589 Function: Returns the current contract allowance. 590 591 Parameters: none 592 593 Response: 594 ``` 595 struct { 596 funds types.Currency (string) 597 hosts uint64 598 period types.BlockHeight (uint64) 599 } 600 ``` 601 'funds' is the number of hastings allocated for file contracts in the given 602 period. 603 604 'hosts' is the number of hosts that contracts will be formed with. 605 606 'period' is the duration of contracts formed. 607 608 #### /renter/allowance [POST] 609 610 Function: Sets the contract allowance. 611 612 Parameters: none 613 ``` 614 funds types.Currency (string) 615 hosts uint64 616 period types.BlockHeight (uint64) 617 ``` 618 'funds' is the number of hastings allocated for file contracts in the given 619 period. 620 621 'hosts' is the number of hosts that contracts will be formed with. 622 623 'period' is the duration of contracts formed. 624 625 Response: standard 626 627 #### /renter/downloads [GET] 628 629 Function: Lists all files in the download queue. 630 631 Parameters: none 632 633 Response: 634 ``` 635 struct { 636 downloads []struct { 637 siapath string 638 destination string 639 filesize uint64 640 received uint64 641 starttime Time (string) 642 } 643 } 644 ``` 645 'siapath' is the siapath given to the file when it was uploaded. 646 647 'destination' is the path that the file will be downloaded to. 648 649 'filesize' is the size of the file being downloaded. 650 651 'received' is the number of bytes downloaded thus far. 652 653 'starttime' is the time at which the download was initiated. 654 655 #### /renter/files 656 657 Function: Lists the status of all files. 658 659 Parameters: none 660 661 Response: 662 ``` 663 struct { 664 files []struct { 665 siapath string 666 filesize uint64 667 available bool 668 renewing bool 669 uploadprogress float64 670 expiration types.BlockHeight (uint64) 671 } 672 } 673 ``` 674 'siapath' is the location of the file in the renter. 675 676 'filesize' is the size of the file in bytes. 677 678 'available' indicates whether or not the file can be downloaded immediately. 679 680 'renewing' indicates whether or not the file's contracts will be renewed 681 automatically by the renter. 682 683 'uploadprogress' is the current upload percentage of the file, including 684 redundancy. In general, files will be available for download before 685 uploadprogress == 100. 686 687 'expiration' is the block height at which the file ceases availability. 688 689 #### /renter/load [POST] 690 691 Function: Load a .sia file into the renter. 692 693 Parameters: 694 ``` 695 source string 696 ``` 697 'source' is the location on disk of the .sia file being loaded. 698 699 Response: 700 ``` 701 struct { 702 filesadded []string 703 } 704 ``` 705 'filesadded' is an array of renter locations of the files contained in the 706 .sia file. 707 708 709 #### /renter/loadascii [POST] 710 711 Function: Load a .sia file into the renter. 712 713 Parameters: 714 ``` 715 asciisia string 716 ``` 717 'asciisia' is the ASCII-encoded .sia file that is being loaded. 718 719 Response: 720 ``` 721 struct { 722 filesadded []string 723 } 724 ``` 725 See /renter/load for a description of 'filesadded' 726 727 #### /renter/share [GET] 728 729 Function: Create a .sia file that can be shared with other people. 730 731 Parameters: 732 ``` 733 siapaths []string 734 destination string 735 ``` 736 'siapaths' is an array of the renter paths to be shared. It is comma-delimited. 737 738 'destination' is the path of the .sia file to be created. It must end in 739 '.sia'. 740 741 Response: standard. 742 743 #### /renter/shareascii [GET] 744 745 Function: Create an ASCII .sia file that can be shared with other people. 746 747 Parameters: 748 ``` 749 siapaths []string 750 ``` 751 'siapaths' is an array of the nicknames to be shared. It is comma-delimited. 752 753 Response: 754 ``` 755 struct { 756 asciisia string 757 } 758 ``` 759 'asciisia' is the ASCII-encoded .sia file. 760 761 #### /renter/delete/{siapath} [POST] 762 763 Function: Deletes a renter file entry. Does not delete any downloads or 764 original files, only the entry in the renter. 765 766 Parameters: 767 ``` 768 siapath string 769 ``` 770 'siapath' is the location of the file in the renter. 771 772 Response: standard 773 774 #### /renter/download/{siapath} [GET] 775 776 Function: Downloads a file. The call will block until the download completes. 777 778 Parameters: 779 ``` 780 siapath string 781 destination string 782 ``` 783 'siapath' is the location of the file in the renter. 784 785 'destination' is the location on disk that the file will be downloaded to. 786 787 Response: standard 788 789 #### /renter/rename/{siapath} [POST] 790 791 Function: Rename a file. Does not rename any downloads or source files, only 792 renames the entry in the renter. 793 794 Parameters: 795 ``` 796 siapath string 797 newsiapath string 798 ``` 799 'siapath' is the current location of the file in the renter. 800 801 'newsiapath' is the new location of the file in the renter. 802 803 Response: standard. 804 805 #### /renter/upload/{siapath} [POST] 806 807 Function: Uploads a file. 808 809 Parameters: 810 ``` 811 siapath string 812 source string 813 ``` 814 'siapath' is the location where the file will reside in the renter. 815 816 'source' is the location on disk of the file being uploaded. 817 818 Response: standard. 819 820 #### /renter/hosts/active [GET] 821 822 Function: Lists all of the active hosts known to the renter. 823 824 Parameters: none 825 826 Response: 827 ``` 828 struct { 829 hosts []struct { 830 netaddress string 831 totalstorage int64 832 minduration types.BlockHeight (uint64) 833 maxduration types.BlockHeight (uint64) 834 windowsize types.BlockHeight (uint64) 835 price types.Currency (string) 836 collateral types.Currency (string) 837 unlockhash types.UnlockHash (string) 838 } 839 } 840 ``` 841 See /renter/hosts/all for a description of each field. 842 843 #### /renter/hosts/all [GET] 844 845 Function: Lists all of the hosts known to the renter. 846 847 Parameters: none 848 849 Response: 850 ``` 851 struct { 852 hosts []struct { 853 netaddress string 854 totalstorage int64 855 minduration types.BlockHeight (uint64) 856 maxduration types.BlockHeight (uint64) 857 windowsize types.BlockHeight (uint64) 858 price types.Currency (string) 859 collateral types.Currency (string) 860 unlockhash types.UnlockHash (string) 861 } 862 } 863 ``` 864 'netaddress' is the network address of the host. 865 866 'totalstorage' is the amount of storage advertised by the host. 867 868 'minduration' is the minimum acceptable contract duration required by the host. 869 870 'maxduration' is the maximum acceptable contract duration required by the host. 871 872 'windowsize' is the minimum acceptable storage proof window size required by 873 the host. 874 875 'price' is the cost of storing data with the host, in hastings/byte/block. 876 877 'collateral' is the collateral supplied by the host when storing data, in 878 hastings/byte/block. 879 880 'unlockhash' is the coin address of the host. 881 882 Transaction Pool 883 ---------------- 884 885 Queries: 886 887 * /transactionpool/transactions [GET] 888 889 #### /transactionpool/transactions [GET] 890 891 Function: Returns all of the transactions in the transaction pool. 892 893 Parameters: none 894 895 Response: 896 ``` 897 struct { 898 transactions []types.Transaction 899 } 900 ``` 901 Please see types/transactions.go for a more detailed explanation of 902 what a transaction looks like. There are many fields. 903 904 905 Wallet 906 ------ 907 908 Queries: 909 910 * /wallet [GET] 911 * /wallet/033x [POST] 912 * /wallet/address [GET] 913 * /wallet/addresses [GET] 914 * /wallet/backup [GET] 915 * /wallet/init [POST] 916 * /wallet/lock [POST] 917 * /wallet/seed [POST] 918 * /wallet/seeds [GET] 919 * /wallet/siacoins [POST] 920 * /wallet/siafunds [POST] 921 * /wallet/siagkey [POST] 922 * /wallet/transaction/{id} [GET] 923 * /wallet/transactions [GET] 924 * /wallet/transactions/{addr} [GET] 925 * /wallet/unlock [POST] 926 927 The first time that the wallet is ever created, the wallet will be unencrypted 928 and locked. The wallet must be initialized and encrypted using a call to 929 /wallet/init. After encrypting the wallet, the wallet must be unlocked. From 930 that point forward (including restarting siad), the wallet will be encrypted, 931 and only the call to /wallet/unlock will be needed. 932 933 #### /wallet [GET] 934 935 Function: Returns basic information about the wallet, such as whether the 936 wallet is locked or unlocked. 937 938 Parameters: none 939 940 Response: 941 ``` 942 struct { 943 encrypted bool 944 unlocked bool 945 946 confirmedsiacoinbalance types.Currency (string) 947 unconfirmedoutgoingsiacoins types.Currency (string) 948 unconfirmedincomingsiacoins types.Currency (string) 949 950 siafundbalance types.Currency (string) 951 siacoinclaimbalance types.Currency (string) 952 } 953 ``` 954 'encrypted' indicates whether the wallet has been encrypted or not. If the 955 wallet has not been encrypted, then no data has been generated at all, and the 956 first time the wallet is unlocked, the password given will be used as the 957 password for encrypting all of the data. 'encrypted' will only be set to false 958 if the wallet has never been unlocked before (the unlocked wallet is still 959 encryped - but the encryption key is in memory). 960 961 'unlocked' indicates whether the wallet is currently locked or unlocked. Some 962 calls become unavailable when the wallet is locked. 963 964 'confirmedsiacoinbalance' is the number of siacoins available to the wallet as 965 of the most recent block in the blockchain. 966 967 'unconfirmedoutgoingsiacoins' is the number of siacoins that are leaving the 968 wallet according to the set of unconfirmed transactions. Often this number 969 appears inflated, because outputs are frequently larger than the number of 970 coins being sent, and there is a refund. These coins are counted as outgoing, 971 and the refund is counted as incoming. The difference in balance can be 972 calculated using 'unconfirmedincomingsiacoins' - 'unconfirmedoutgoingsiacoins' 973 974 'unconfirmedincomingsiacoins' is the number of siacoins are entering the wallet 975 according to the set of unconfirmed transactions. This number is often inflated 976 by outgoing siacoins, because outputs are frequently larger than the amount 977 being sent. The refund will be included in the unconfirmed incoming siacoins 978 balance. 979 980 'siafundbalance' is the number of siafunds available to the wallet as 981 of the most recent block in the blockchain. 982 983 'siacoinclaimbalance' is the number of siacoins that can be claimed from the 984 siafunds as of the most recent block. Because the claim balance increases every 985 time a file contract is created, it is possible that the balance will increase 986 before any claim transaction is confirmed. 987 988 #### /wallet/033x [POST] 989 990 Function: Load a v0.3.3.x wallet into the current wallet, harvesting all of the 991 secret keys. All spendable addresses in the loaded wallet will become spendable 992 from the current wallet. 993 994 Parameters: 995 ``` 996 source string 997 encryptionpassword string 998 ``` 999 'source' is the location on disk of the v0.3.3.x wallet that is being loaded. 1000 1001 'encryptionpassword' is the encryption key of the wallet. An error will be 1002 returned if the wrong key is provided. 1003 1004 Response: standard. 1005 1006 #### /wallet/address [GET] 1007 1008 Function: Get a new address from the wallet generated by the primary seed. An 1009 error will be returned if the wallet is locked. 1010 1011 Parameters: none 1012 1013 Response: 1014 ``` 1015 struct { 1016 address types.UnlockHash (string) 1017 } 1018 ``` 1019 'address' is a wallet address that can receive siacoins or siafunds. 1020 1021 #### /wallet/addresses [GET] 1022 1023 Function: Fetch the list of addresses from the wallet. 1024 1025 Parameters: none 1026 1027 Response: 1028 ``` 1029 struct { 1030 addresses []types.UnlockHash (string) 1031 } 1032 ``` 1033 'addresses' is an array of wallet addresses. 1034 1035 #### /wallet/backup [GET] 1036 1037 Function: Create a backup of the wallet settings file. Though this can easily 1038 be done manually, the settings file is often in an unknown or difficult to find 1039 location. The /wallet/backup call can spare users the trouble of needing to 1040 find their wallet file. 1041 1042 Parameters: 1043 ``` 1044 destination string 1045 ``` 1046 'destination' is the location on disk where the file will be saved. 1047 1048 Response: standard 1049 1050 #### /wallet/init [POST] 1051 1052 Function: Initialize the wallet. After the wallet has been initialized once, it 1053 does not need to be initialized again, and future calls to /wallet/init will 1054 return an error. The encryption password is provided by the api call. If the 1055 password is blank, then the password will be set to the same as the seed. 1056 1057 Parameters: 1058 ``` 1059 encryptionpassword string 1060 dictionary string 1061 ``` 1062 'encryptionpassword' is the password that will be used to encrypt the wallet. 1063 All subsequent calls should use this password. If left blank, the seed that 1064 gets returned will also be the encryption password. 1065 1066 'dictionary' is the name of the dictionary that should be used when encoding 1067 the seed. 'english' is the most common choice when picking a dictionary. 1068 1069 Response: 1070 ``` 1071 struct { 1072 primaryseed string 1073 } 1074 ``` 1075 'primaryseed' is the dictionary encoded seed that is used to generate addresses 1076 that the wallet is able to spend. 1077 1078 #### /wallet/seed [POST] 1079 1080 Function: Give the wallet a seed to track when looking for incoming 1081 transactions. The wallet will be able to spend outputs related to addresses 1082 created by the seed. The seed is added as an auxiliary seed, and does not 1083 replace the primary seed. Only the primary seed will be used for generating new 1084 addresses. 1085 1086 Parameters: 1087 ``` 1088 encryptionpassword string 1089 dictionary string 1090 seed string 1091 ``` 1092 'encryptionpassword' is the key that is used to encrypt the new seed when it is 1093 saved to disk. 1094 1095 'dictionary' is the name of the dictionary that should be used when encoding 1096 the seed. 'english' is the most common choice when picking a dictionary. 1097 1098 'seed' is the dictionary-encoded phrase that corresponds to the seed being 1099 added to the wallet. 1100 1101 Response: standard 1102 1103 #### /wallet/seeds [GET] 1104 1105 Function: Return a list of seeds in use by the wallet. The primary seed is the 1106 only seed that gets used to generate new addresses. This call is unavailable 1107 when the wallet is locked. 1108 1109 Parameters: 1110 ``` 1111 dictionary string 1112 ``` 1113 'dictionary' is the name of the dictionary that should be used when encoding 1114 the seed. 'english' is the most common choice when picking a dictionary. 1115 1116 Response: 1117 ``` 1118 struct { 1119 primaryseed mnemonics.Phrase (string) 1120 addressesremaining int 1121 allseeds []mnemonics.Phrase ([]string) 1122 } 1123 ``` 1124 'primaryseed' is the seed that is actively being used to generate new addresses 1125 for the wallet. 1126 1127 'addressesremaining' is the number of addresses that remain in the primary seed 1128 until exhaustion has been reached. Once exhaustion has been reached, new 1129 addresses will continue to be generated but they will be more difficult to 1130 recover in the event of a lost wallet file or encryption password. 1131 1132 'allseeds' is an array of all seeds that the wallet references when scanning the 1133 blockchain for outputs. The wallet is able to spend any output generated by any 1134 of the seeds, however only the primary seed is being used to generate new 1135 addresses. 1136 1137 A seed is an encoded version of a 128 bit random seed. The output is 15 words 1138 chosen from a small dictionary as indicated by the input. The most common 1139 choice for the dictionary is going to be 'english'. The underlying seed is the 1140 same no matter what dictionary is used for the encoding. The encoding also 1141 contains a small checksum of the seed, to help catch simple mistakes when 1142 copying. The library 1143 [entropy-mnemonics](https://github.com/NebulousLabs/entropy-mnemonics) is used 1144 when encoding. 1145 1146 #### /wallet/siacoins [POST] 1147 1148 Function: Send siacoins to an address. The outputs are arbitrarily selected 1149 from addresses in the wallet. 1150 1151 Parameters: 1152 ``` 1153 amount int 1154 destination types.UnlockHash (string) 1155 ``` 1156 'amount' is the number of hastings being sent. A hasting is the smallest unit 1157 in Sia. There are 10^24 hastings in a siacoin. 1158 1159 'destination' is the address that is receiving the coins. 1160 1161 Response: 1162 ``` 1163 struct { 1164 transactionids []types.TransactionID ([]string) 1165 } 1166 ``` 1167 'transactionids' are the ids of the transactions that were created when sending 1168 the coins. The last transaction contains the output headed to the 1169 'destination'. 1170 1171 #### /wallet/siafunds [POST] 1172 1173 Function: Send siafunds to an address. The outputs are arbitrarily selected 1174 from addresses in the wallet. Any siacoins available in the siafunds being sent 1175 (as well as the siacoins available in any siafunds that end up in a refund 1176 address) will become available to the wallet as siacoins after 144 1177 confirmations. To access all of the siacoins in the siacoin claim balance, send 1178 all of the siafunds to an address in your control (this will give you all the 1179 siacoins, while still letting you control the siafunds). 1180 1181 Parameters: 1182 ``` 1183 amount int 1184 destination string 1185 ``` 1186 'amount' is the number of siafunds being sent. 1187 1188 'destination' is the address that is receiving the funds. 1189 1190 Response: 1191 ``` 1192 struct { 1193 transactionids []types.TransactionID ([]string) 1194 } 1195 ``` 1196 'transactionids' are the ids of the transactions that were created when sending 1197 the coins. The last transaction contains the output headed to the 1198 'destination'. 1199 1200 #### /wallet/siagkey [POST] 1201 1202 Function: Load a key into the wallet that was generated by siag. Most siafunds 1203 are currently in addresses created by siag. 1204 1205 Parameters: 1206 ``` 1207 encryptionpassword string 1208 keyfiles string 1209 ``` 1210 'encryptionpassword' is the key that is used to encrypt the siag key when it is 1211 imported to the wallet. 1212 1213 'keyfiles' is a list of filepaths that point to the keyfiles that make up the 1214 siag key. There should be at least one keyfile per required signature. The 1215 filenames need to be commna separated (no spaces), which means filepaths that 1216 contain a comma are not allowed. 1217 1218 #### /wallet/lock [POST] 1219 1220 Function: Locks the wallet, wiping all secret keys. After being locked, the 1221 keys are encrypted. Queries for the seed, to send siafunds, and related queries 1222 become unavailable. Queries concerning transaction history and balance are 1223 still available. 1224 1225 Parameters: none 1226 1227 Response: standard. 1228 1229 #### /wallet/transaction/{id} [GET] 1230 1231 Function: Get the transaction associated with a specific transaction id. 1232 1233 Parameters: 1234 ``` 1235 id string 1236 ``` 1237 'id' is the ID of the transaction being requested. 1238 1239 Response: 1240 ``` 1241 struct { 1242 transaction modules.ProcessedTransaction 1243 } 1244 ``` 1245 1246 Processed transactions are transactions that have been processed by the wallet 1247 and given more information, such as a confirmation height and a timestamp. 1248 Processed transactions will always be returned in chronological order. 1249 1250 A processed transaction takes the following form: 1251 ``` 1252 struct modules.ProcessedTransaction { 1253 transaction types.Transaction 1254 transactionid types.TransactionID (string) 1255 confirmationheight types.BlockHeight (int) 1256 confirmationtimestamp types.Timestamp (uint64) 1257 1258 inputs []modules.ProcessedInput 1259 outputs []modules.ProcessedOutput 1260 } 1261 ``` 1262 'transaction' is a types.Transaction, and is defined in types/transactions.go 1263 1264 'transactionid' is the id of the transaction from which the wallet transaction 1265 was derived. 1266 1267 'confirmationheight' is the height at which the transaction was confirmed. The 1268 height will be set to 'uint64max' if the transaction has not been confirmed. 1269 1270 'confirmationtimestamp' is the time at which a transaction was confirmed. The 1271 timestamp is an unsigned 64bit unix timestamp, and will be set to 'uint64max' 1272 if the transaction is unconfirmed. 1273 1274 'inputs' is an array of processed inputs detailing the inputs to the 1275 transaction. More information below. 1276 1277 'outputs' is an array of processed outputs detailing the outputs of 1278 the transaction. Outputs related to file contracts are excluded. 1279 1280 A modules.ProcessedInput takes the following form: 1281 ``` 1282 struct modules.ProcessedInput { 1283 fundtype types.Specifier (string) 1284 walletaddress bool 1285 relatedaddress types.UnlockHash (string) 1286 value types.Currency (string) 1287 } 1288 ``` 1289 1290 'fundtype' indicates what type of fund is represented by the input. Inputs can 1291 be of type 'siacoin input', and 'siafund input'. 1292 1293 'walletaddress' indicates whether the address is owned by the wallet. 1294 1295 'relatedaddress' is the address that is affected. For inputs (outgoing money), 1296 the related address is usually not important because the wallet arbitrarily 1297 selects which addresses will fund a transaction. For outputs (incoming money), 1298 the related address field can be used to determine who has sent money to the 1299 wallet. 1300 1301 'value' indicates how much money has been moved in the input or output. 1302 1303 A modules.ProcessedOutput takes the following form: 1304 ``` 1305 struct modules.ProcessedOutput { 1306 fundtype types.Specifier (string) 1307 maturityheight types.BlockHeight (int) 1308 walletaddress bool 1309 relatedaddress types.UnlockHash (string) 1310 value types.Currency (string) 1311 } 1312 ``` 1313 1314 'fundtype' indicates what type of fund is represented by the output. Outputs 1315 can be of type 'siacoin output', 'siafund output', and 'claim output'. Siacoin 1316 outputs and claim outputs both relate to siacoins. Siafund outputs relate to 1317 siafunds. Another output type, 'miner payout', points to siacoins that have been 1318 spent on a miner payout. Because the destination of the miner payout is determined by 1319 the block and not the transaction, the data 'maturityheight', 'walletaddress', 1320 and 'relatedaddress' are left blank. 1321 1322 'maturityheight' indicates what height the output becomes available to be 1323 spent. Siacoin outputs and siafund outputs mature immediately - their maturity 1324 height will always be the confirmation height of the transaction. Claim outputs 1325 cannot be spent until they have had 144 confirmations, thus the maturity height 1326 of a claim output will always be 144 larger than the confirmation height of the 1327 transaction. 1328 1329 'walletaddress' indicates whether the address is owned by the wallet. 1330 1331 'relatedaddress' is the address that is affected. 1332 1333 'value' indicates how much money has been moved in the input or output. 1334 1335 #### /wallet/transactions [GET] 1336 1337 Function: Return a list of transactions related to the wallet. 1338 1339 Parameters: 1340 ``` 1341 startheight types.BlockHeight (uint64) 1342 endheight types.BlockHeight (uint64) 1343 ``` 1344 'startheight' refers to the height of the block where transaction history 1345 should begin. 1346 1347 'endheight' refers to the height of of the block where the transaction history 1348 should end. If 'endheight' is greater than the current height, all transactions 1349 up to and including the most recent block will be provided. 1350 1351 Response: 1352 ``` 1353 struct { 1354 confirmedtransactions []modules.ProcessedTransaction 1355 unconfirmedtransactions []modules.ProcessedTransaction 1356 } 1357 ``` 1358 'confirmedtransactions' lists all of the confirmed transactions appearing between 1359 height 'startheight' and height 'endheight' (inclusive). 1360 1361 'unconfirmedtransactions' lists all of the unconfirmed transactions. 1362 1363 #### /wallet/transactions/{addr} [GET] 1364 1365 Function: Return all of the transaction related to a specific address. 1366 1367 Parameters: 1368 ``` 1369 addr types.UnlockHash 1370 ``` 1371 'addr' is the unlock hash (i.e. wallet address) whose transactions are being 1372 requested. 1373 1374 Response: 1375 ``` 1376 struct { 1377 transactions []modules.ProcessedTransaction. 1378 } 1379 ``` 1380 'transactions' is a list of processed transactions that relate to the supplied 1381 address. See the documentation for '/wallet/transaction' for more information. 1382 1383 #### /wallet/unlock [POST] 1384 1385 Function: Unlock the wallet. The wallet is capable of knowing whether the 1386 correct password was provided. 1387 1388 Parameters: 1389 ``` 1390 encryptionpassword string 1391 ``` 1392 'encryptionpassword' is the password that gets used to decrypt the file. Most 1393 frequently, the encryption password is the same as the primary wallet seed. 1394 1395 Response: standard