摘要:我們已經(jīng)創(chuàng)建過一個回復消息的機器人和一個能自動支付比特幣的機器人通過本教程的學習,你可以學到如下內(nèi)容如何創(chuàng)建一個比特幣錢包如何讀取比特幣錢包的余額如何支付比特幣并即時確認如何將的比特幣提現(xiàn)到你的冷錢包或第三方交易所前期準備你要有一個賬戶。
我們已經(jīng)創(chuàng)建過一個回復消息的機器人和一個能自動支付比特幣的機器人.
通過本教程的學習,你可以學到如下內(nèi)容如何創(chuàng)建一個比特幣錢包.
如何讀取比特幣錢包的余額.
如何支付比特幣并即時確認.
如何將Mixin Network的比特幣提現(xiàn)到你的冷錢包或第三方交易所.
前期準備:你要有一個Mixin Network賬戶。下面的代碼創(chuàng)建一個帳號,并寫到csv文件里。
if File.file?(WALLET_NAME) p "mybitcoin_wallet.csv has already existed !" next end yaml_hash = YAML.load_file("./config.yml") MixinBot.client_id = yaml_hash["MIXIN_CLIENT_ID"] MixinBot.session_id = yaml_hash["MIXIN_SESSION_ID"] MixinBot.client_secret = yaml_hash["MIXIN_CLIENT_SECRET"] MixinBot.pin_token = yaml_hash["MIXIN_PIN_TOKEN"] MixinBot.private_key = yaml_hash["MIXIN_PRIVATE_KEY"] access_token = MixinBot.api.access_token("GET","/","") rsa_key = OpenSSL::PKey::RSA.new(1024) private_key = rsa_key.to_pem() p private_key public_key = rsa_key.public_key.to_pem secret_client = public_key.sub("-----BEGIN PUBLIC KEY----- ","").sub(" -----END PUBLIC KEY----- ","") reqInfo = MixinBot.api.create_user("ruby bot",secret_client) p reqInfo["data"]["pin_token"] p reqInfo["data"]["user_id"] p reqInfo["data"]["session_id"] CSV.open(WALLET_NAME, "wb") do |csv| csv << [private_key, reqInfo["data"]["pin_token"], reqInfo["data"]["session_id"], reqInfo["data"]["user_id"]] end
上面的語句會在本地創(chuàng)建一個RSA密鑰對,然后調用Mixin Network來創(chuàng)建帳號,最后保存帳號信息到csv文件.
現(xiàn)在你需要小心保管好你的帳號信息,在讀取該賬戶的比特幣資產(chǎn)余額或者進行其他操作時,將需要用到這些信息.
給新建的帳號創(chuàng)建一個比特幣錢包新賬號并不默認內(nèi)置比特幣錢包, 現(xiàn)在讀一下比特幣余額就可以創(chuàng)建一個比特幣錢包。
if cmd == "2" table = CSV.read(WALLET_NAME) MixinBot.client_id = table[0][3] MixinBot.session_id = table[0][2] MixinBot.pin_token = table[0][1] MixinBot.private_key = table[0][0] botAssetsInfo = MixinBot.api.read_asset(BTC_ASSET_ID) p botAssetsInfo p "The BTC wallet address is " + botAssetsInfo["data"]["public_key"] p "The BTC wallet balance is " + botAssetsInfo["data"]["balance"] end
創(chuàng)建的帳號的比特幣資產(chǎn)詳細信息如下,其中public key就是比特幣的存幣地址:
Make your choose(eg: q for Exit!): 2 {"data"=>{"type"=>"asset", "asset_id"=>"c6d0c728-2624-429b-8e0d-d9d19b6592fa", "chain_id"=>"c6d0c728-2624-429b-8e0d-d9d19b6592fa", "symbol"=>"BTC", "name"=>"Bitcoin", "icon_url"=>"https://images.mixin.one/HvYGJsV5TGeZ-X9Ek3FEQohQZ3fE9LBEBGcOcn4c4BNHovP4fW4YB97Dg5LcXoQ1hUjMEgjbl1DPlKg1TW7kK6XP=s128", "balance"=>"0", "public_key"=>"1MQLQG1FshdVaQrDE36FLGabCitE3vPUA", "account_name"=>"", "account_tag"=>"", "price_btc"=>"1", "price_usd"=>"7948.30287759", "change_btc"=>"0", "change_usd"=>"0.006197123302394101", "asset_key"=>"c6d0c728-2624-429b-8e0d-d9d19b6592fa", "confirmations"=>6, "capitalization"=>0}} "The BTC wallet address is 1MQLQG1FshdVaQrDE36FLGabCitE3vPUA" "The BTC wallet balance is 0" -------------------------------------------------------------------------
這個API能夠提供若干與比特幣有關的信息:
存幣地址:[public_key]
Logo: [icon_url]
資產(chǎn)名字:[name]
資產(chǎn)在Mixin Network的uuid: [asset_key]
對美元的價格(Coinmarketcap.com提供): [price_usd]
存幣時確認的區(qū)塊數(shù)量:[confirmations]
比特幣私鑰呢?比特幣的私鑰呢?這個私鑰被Mixin Network通過多重簽名保護,所以對用戶來說是不可見的,比特幣資產(chǎn)的提現(xiàn)和轉賬都需要用戶提供正確的的RSA簽名,PIN代碼與會話密鑰才能完成.
不只是比特幣,還有以太坊,EOS等這個帳號不只支持比特幣,還支持以太坊,EOS等, 完整的區(qū)塊鏈支持列表. 這個賬戶同時也支持所有的 ERC20 代幣與 EOS 代幣.
創(chuàng)建其它的幣的錢包與創(chuàng)建比特幣錢包過程一樣,讀對應的資產(chǎn)余額就可以.
Mixin Network 當前支持的加密貨幣 (2019-02-19)crypto | uuid in Mixin Network |
---|---|
EOS | 6cfe566e-4aad-470b-8c9a-2fd35b49c68d |
CNB | 965e5c6e-434c-3fa9-b780-c50f43cd955c |
BTC | c6d0c728-2624-429b-8e0d-d9d19b6592fa |
ETC | 2204c1ee-0ea2-4add-bb9a-b3719cfff93a |
XRP | 23dfb5a5-5d7b-48b6-905f-3970e3176e27 |
XEM | 27921032-f73e-434e-955f-43d55672ee31 |
ETH | 43d61dcd-e413-450d-80b8-101d5e903357 |
DASH | 6472e7e3-75fd-48b6-b1dc-28d294ee1476 |
DOGE | 6770a1e5-6086-44d5-b60f-545f9d9e8ffd |
LTC | 76c802a2-7c88-447f-a93e-c29c9e5dd9c8 |
SC | 990c4c29-57e9-48f6-9819-7d986ea44985 |
ZEN | a2c5d22b-62a2-4c13-b3f0-013290dbac60 |
ZEC | c996abc9-d94e-4494-b1cf-2a3fd3ac5714 |
BCH | fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0 |
EOS的存幣地址與其它的幣有些不同,它由兩部分組成: account_name and account tag, 如果你向Mixin Network存入EOS,你需要填兩項數(shù)據(jù): account name 是eoswithmixin,備注里輸入你的account_tag,比如0aa2b00fad2c69059ca1b50de2b45569.
EOS的資產(chǎn)余額返回結果如下:
Make your choose(eg: q for Exit!): 3 {"data"=>{"type"=>"asset", "asset_id"=>"6cfe566e-4aad-470b-8c9a-2fd35b49c68d", "chain_id"=>"6cfe566e-4aad-470b-8c9a-2fd35b49c68d", "symbol"=>"EOS", "name"=>"EOS", "icon_url"=>"https://images.mixin.one/a5dtG-IAg2IO0Zm4HxqJoQjfz-5nf1HWZ0teCyOnReMd3pmB8oEdSAXWvFHt2AJkJj5YgfyceTACjGmXnI-VyRo=s128", "balance"=>"0", "public_key"=>"", "account_name"=>"eoswithmixin", "account_tag"=>"60ec682616408d9486b5975a1361e269", "price_btc"=>"0.00079077", "price_usd"=>"6.28647972", "change_btc"=>"0.004235601507246285", "change_usd"=>"0.00974554134353926", "asset_key"=>"eosio.token:EOS", "confirmations"=>64, "capitalization"=>0}} "The EOS wallet address is eoswithmixin 60ec682616408d9486b5975a1361e269" "The EOS wallet balance is 0" -------------------------------------------------------------------------存入比特幣與讀取比特幣余額
現(xiàn)在,你可以向比特幣的錢包存幣了。
當然,在比特幣網(wǎng)絡里轉幣,手續(xù)費是相當貴的,費用的中位數(shù)在0.001BTC,按當前4000美元的價格,在4美元左右,有一個方便的辦法,如果你有Mixin Messenger帳號,里面并且有比特幣的話,可以直接提現(xiàn)比特幣到新創(chuàng)建的帳號的比特幣充值地址,它們在同一個Mixin Network網(wǎng)絡內(nèi),手續(xù)費為0,而且1秒到賬。
下面的代碼,可以讀取比特幣錢包余額.
table = CSV.read(WALLET_NAME) MixinBot.client_id = table[0][3] MixinBot.session_id = table[0][2] MixinBot.pin_token = table[0][1] MixinBot.private_key = table[0][0] botAssetsInfo = MixinBot.api.read_asset(BTC_ASSET_ID) p botAssetsInfo p "The BTC wallet address is " + botAssetsInfo["data"]["public_key"] p "The BTC wallet balance is " + botAssetsInfo["data"]["balance"]Mixin Network網(wǎng)內(nèi)免手續(xù)費的,并且即時確認
任何幣在Mixin Network內(nèi)部的交易,都是無手續(xù)費的,并且立刻到賬。
前期準備: 賬戶設置了PIN
對于新創(chuàng)建的帳號,我們通過updatePin來設置新PIN碼, 代碼如下:
table = CSV.read(WALLET_NAME) puts table[0][1] MixinBot.client_id = table[0][3] MixinBot.session_id = table[0][2] MixinBot.pin_token = table[0][1] MixinBot.private_key = table[0][0] pinInfo = MixinBot.api.update_pin("",DEFAULT_PIN) p pinInfoMixin Network帳號之間的比特幣支付
通過Mixin Messenger,我們可以先轉比特幣給機器人,然后讓機器人轉幣給新用戶。
if cmd == "teb" yaml_hash = YAML.load_file("./config.yml") MixinBot.client_id = yaml_hash["MIXIN_CLIENT_ID"] MixinBot.session_id = yaml_hash["MIXIN_SESSION_ID"] MixinBot.client_secret = yaml_hash["MIXIN_CLIENT_SECRET"] MixinBot.pin_token = yaml_hash["MIXIN_PIN_TOKEN"] MixinBot.private_key = yaml_hash["MIXIN_PRIVATE_KEY"] table = CSV.read(WALLET_NAME) wallet_userid = table[0][3] botAssetsInfo = MixinBot.api.read_asset(EOS_ASSET_ID) if botAssetsInfo["data"]["balance"].to_f > 0 transInfo = MixinBot.api.create_transfer(MixinBot.api.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]), { asset_id: EOS_ASSET_ID, opponent_id: wallet_userid, amount: botAssetsInfo["data"]["balance"], trace_id: SecureRandom.uuid, memo: "from ruby" }) p transInfo end end
讀取Bitcoin的余額,來確認比特幣是不是轉成功了!
botAssetsInfo = MixinBot.api.read_assets()如何將比特幣存入你的冷錢包或者第三方交易所
如果你希望將幣存入你的冷錢包或者第三方交易所, 先要得到冷錢包或者你在第三方交易所的錢包地址,然后將錢包地址提交到Mixin Network.
要點提示: 提現(xiàn)是需要支付收續(xù)費的,準備好比特幣包地址!
增加目的錢包地址到Mixin Network調用createAddress API, 將會返回一個address_id,下一步的提現(xiàn)操作會用到這個id。
if cmd == "wb" table = CSV.read(WALLET_NAME) MixinBot.client_id = table[0][3] MixinBot.session_id = table[0][2] MixinBot.pin_token = table[0][1] MixinBot.private_key = table[0][0] addressInfo = MixinBot.api.create_withdraw_address(BTC_ASSET_ID, DEFAULT_PIN, BTC_WALLET_ADDR, "","", "from ruby") p addressInfo p "The address id is " + addressInfo["data"]["address_id"] + " it is needed by read fee!" end
這里的 14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C 就是一個比特幣錢包地址, 如下所示,提現(xiàn)費用是0.0025738 BTC, address_id 是"345855b5-56a5-4f3b-ba9e-d99601ef86c1".
Make your choose:wb wb {"type":"address","address_id":"58860d12-cbdc-40ae-8a4a-b0fc72f418b3", "asset_id":"c6d0c728-2624-429b-8e0d-d9d19b6592fa","public_key":"14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C", "label":"hi","account_name":"","account_tag":"","fee":"0.00118846","reserve":"0","dust":"0.0001", "updated_at":"2019-04-16T06:12:15.686517454Z"} ------------------------BTC---Withdrawal---Information--------------------------- The BTC Witchdrawal address is 14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C The BTC withdraw fee is 0.00118846創(chuàng)建提現(xiàn)地址成功后,你可以用readAddress讀取最新的提現(xiàn)費。
addressInfo = MixinBot.api.get_withdraw_address(addressInfo["data"]["address_id"]) p addressInfo提交提現(xiàn)請求,Mixin Network會即時處理提現(xiàn)請求.
提交提現(xiàn)請求到 Mixin Network, withdrawAddress.address_id 就是createAddress創(chuàng)建的。
if cmd == "wb" table = CSV.read(WALLET_NAME) MixinBot.client_id = table[0][3] MixinBot.session_id = table[0][2] MixinBot.pin_token = table[0][1] MixinBot.private_key = table[0][0] addressInfo = MixinBot.api.create_withdraw_address(BTC_ASSET_ID, DEFAULT_PIN, BTC_WALLET_ADDR, "","", "from ruby") p addressInfo p "The address id is " + addressInfo["data"]["address_id"] + " it is needed by read fee!" addressInfo2 = MixinBot.api.del_withdraw_address(addressInfo["data"]["address_id"], DEFAULT_PIN) p addressInfo2 withdrawInfo = MixinBot.api.withdrawals(addressInfo["data"]["address_id"], DEFAULT_PIN, "0.1", SecureRandom.uuid,"from ruby") p withdrawInfo end可以通過blockchain explore來查看進度.
完整的代碼在這兒
文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/24701.html
摘要:創(chuàng)建比特幣錢包需要一組優(yōu)秀的程序員。如何使用流行的庫構建自己的比特幣錢包應用程序創(chuàng)建比特幣錢包應用程序的一種方法是依賴現(xiàn)有工具。具有以下功能它允許開發(fā)人員使用密碼加密創(chuàng)建比特幣錢包應用程序。 盡管目前加密貨幣市場相當黯淡,但比特幣和其他山寨幣繼續(xù)受歡迎。每天都有新的交易者加入市場,希望能夠在下一個價格高漲時獲利。 隨著市場的突飛猛進,開發(fā)商也在獲益。新交易者的首要任務是設置比特幣錢包。...
摘要:創(chuàng)建比特幣錢包需要一組優(yōu)秀的程序員。如何使用流行的庫構建自己的比特幣錢包應用程序創(chuàng)建比特幣錢包應用程序的一種方法是依賴現(xiàn)有工具。具有以下功能它允許開發(fā)人員使用密碼加密創(chuàng)建比特幣錢包應用程序。 盡管目前加密貨幣市場相當黯淡,但比特幣和其他山寨幣繼續(xù)受歡迎。每天都有新的交易者加入市場,希望能夠在下一個價格高漲時獲利。 隨著市場的突飛猛進,開發(fā)商也在獲益。新交易者的首要任務是設置比特幣錢包。...
摘要:是一個免費的極速的端對端加密數(shù)字貨幣交易系統(tǒng)官方資源匯總課程簡介創(chuàng)建一個機器人比特幣開發(fā)教程機器人接受比特幣并立即退還用戶比特幣開發(fā)教程創(chuàng)建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言匯總比特幣開發(fā)教程 showImg(https://segmentfault.com/img/remote/1460000019234638?w=1200&h=659...
閱讀 1597·2023-04-25 14:12
閱讀 1069·2021-08-27 16:24
閱讀 2532·2019-08-30 15:44
閱讀 2911·2019-08-30 13:16
閱讀 1664·2019-08-29 14:10
閱讀 964·2019-08-29 13:54
閱讀 1295·2019-08-29 13:09
閱讀 1801·2019-08-26 18:37