XMR === * [name=Ander Liu] ###### tags: `Blockchain` [TOC] ## Basic info * Source code: https://github.com/monero-project/monero * Releases: * https://web.getmonero.org/downloads/ * https://github.com/monero-project/monero/releases * Block Explorer: https://moneroblocks.info * Block Explorer (Testnet): https://community.xmr.to/explorer/testnet/ ## Testnet Faucets - https://dis.gratis (好像不能用了) - 要測試幣就自己挖吧 ## monerod * `monerod` handles the blockchain * reference: https://web.getmonero.org/resources/user-guides/vps_run_node.html * 如果要跑 testnet, 就要加上 --testnet ```bash= $ ./monerod --detach $ ./monerod --testnet --detach ``` ## monero-wallet-rpc * `monero-wallet-rpc` handles the account ```bash= $ ./monero-wallet-rpc --wallet-dir="..." --rpc-bind-port=xxxxx --disable-rpc-login --detach $ ./monero-wallet-rpc --wallet-dir="..." --rpc-bind-port=xxxxx --disable-rpc-login --testnet --detach ``` :::info * testnet 要記得加上 --testnet * port 的部分隨便設就好,18080~18082, 28080~28082已經被 monerod 的 RPC 用掉了 ::: ## 查詢區塊高度 (get_block_count) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}' -H 'Content-Type: application/json' ``` * return: ``` { "id": "0", "jsonrpc": "2.0", "result": { "count": 1889511, "status": "OK" } } ``` :::warning * 這裡的 port 要填 monerod 的,因為是跟 blockchain 查詢 * mainnet 為 18081 * testnet 為 28081 ::: ## 創建錢包 (create_wallet) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"create_wallet","params":{"filename":"mytestwallet","password":"mytestpassword","language":"English"}}' -H 'Content-Type: application/json' ``` ## 創建帳戶 (create_account) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"create_account","params":{"label":"Secondary account"}}' -H 'Content-Type: application/json' ``` ## 創建地址 (create_address) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"create_address","params":{"account_index":0,"label":"new-sub"}}' -H 'Content-Type: application/json' ``` :::info * account_index 填入要創建地址的帳戶的 index ::: ## 查詢餘額 (get_balance) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_balance","params":{"account_index":0,"address_indices":[0,1]}}' -H 'Content-Type: application/json' ``` :::info * account_index 填入要查詢餘額的帳戶的 index * address_indices 填入要查詢餘額的地址的 index ::: * result ```bash= { "id": "0", "jsonrpc": "2.0", "result": { "balance": 125371080075326, "blocks_to_unlock": 54, "multisig_import_needed": false, "per_subaddress": [{ "account_index": 0, "address": "A24WLm......", "address_index": 0, "balance": 125371080075326, "blocks_to_unlock": 54, "label": "Primary account", "num_unspent_outputs": 22, "unlocked_balance": 119676031257562 },{ "account_index": 0, "address": "Bbra3o......", "address_index": 1, "balance": 0, "blocks_to_unlock": 0, "label": "new-sub", "num_unspent_outputs": 0, "unlocked_balance": 0 }], "unlocked_balance": 119676031257562 } } ``` ## 挖礦 (start_mining) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"start_mining","params":{"threads_count":1,"do_background_mining":true,"ignore_battery":false}}' -H 'Content-Type: application/json' ``` ## Transaction (transfer) ```bash= $ curl -X POST http://127.0.0.1:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"transfer","params":{"destinations":[{"amount":100000000000,"address":"Bbra3o......"}],"account_index":0,"subaddr_indices":[0],"priority":0,"ring_size":7,"get_tx_key": true}}' -H 'Content-Type: application/json' ``` :::info * ammount 填金額 * address 填目標地址 * account_index 填入要交易的帳戶的 index ::: * result: ```bash= { "id": "0", "jsonrpc": "2.0", "result": { "amount": 100000000000, "fee": 98260000, "multisig_txset": "", "tx_blob": "", "tx_hash": "41c492d1ee56f1f50608bb14c8ea8016143b1ff71ad9e22099d22aa10ae9c775", "tx_key": "62d817d2e5c2e6665b942a8193dc479b180693990bb90513ba84a8563cf0af0b", "tx_metadata": "", "unsigned_txset": "" } } ``` :::info * tx_hash 即為 txid ::: ## 查詢交易結果 (get_transfer_by_txid) ```bash= $ curl -X POST http://localhost:xxxxx/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_transfer_by_txid","params":{"txid":"41c492......"}}' -H 'Content-Type: application/json' ``` * result: ```bash= { "id": "0", "jsonrpc": "2.0", "result": { "transfer": { "address": "A24WLm......", "amount": 0, "confirmations": 14, "destinations": [{ "address": "Bbra3o......", "amount": 100000000000 }], "double_spend_seen": false, "fee": 98260000, "height": 1267122, "note": "", "payment_id": "0000000000000000", "subaddr_index": { "major": 0, "minor": 0 }, "subaddr_indices": [{ "major": 0, "minor": 0 }], "suggested_confirmations_threshold": 0, "timestamp": 1564556186, "txid": "41c492d1ee56f1f50608bb14c8ea8016143b1ff71ad9e22099d22aa10ae9c775", "type": "out", "unlock_time": 0 } } } ``` :::info * height 即為交易的區塊高度 * confirmations 即為交易後已經產生了幾個區塊 ::: ## warning :::danger * XMR 使用 UTXO,並且 RPC 只能對自己錢包做交易 ::: ## Reference * [Official Website](https://web.getmonero.org) * https://web.getmonero.org/resources/user-guides/ * https://monerodocs.org/interacting/monerod-reference/ * RPC: * https://web.getmonero.org/resources/developer-guides/daemon-rpc.html * https://web.getmonero.org/resources/developer-guides/wallet-rpc.html ## Homepage * [Homepage](/@NDR/Homepage)