区块链钱包API提供了一个简单的界面,商家可以使用该界面以编程方式与其钱包进行交互。
使用此API,将需要运行小型本地服务,该服务负责管理您的Blockchain Wallet。应用程序通过HTTP API调用在本地与该服务进行交互。获取有关GitHub的完整设置说明:https://github.com/blockchain/service-my-wallet-v3
create_wallet方法可用于创建新的blockchain.info比特币钱包。
网址: http:// localhost:3000 / api / v2 / create
方法: POST或GET
响应:200 OK,应用程序/ json
{
"guid": "4b8cd8e9-9480-44cc-b7f2-527e98ee3287",
"address": "12AaMuRnzw6vW6s2KPRAGeX53meTf8JbZS",
"label": "Main address"
}
从您的钱包中将比特币发送到另一个比特币地址。所有交易均包括0.0001 BTC矿工费。
所有比特币价值均以中本聪为单位,即除以100000000可获得以BTC为单位的金额。所有请求的基本URL:https : //blockchain.info/merchant/$guid/。 $guid应该替换为您的Blockchain Wallet标识符(在登录页面上找到)。
http:// localhost:3000 / merchant / $ guid / payment?password = $ main_password&second_password = $ second_password&to = $ address&amount = $ amount&from = $ from&fee = $ fee
响应:200 OK,应用程序/ json
{
"message" : "Response Message" , "tx_hash": "Transaction Hash", "notice" : "Additional Message" }
{
"message" : "Sent 0.1 BTC to 1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq" , "tx_hash" : "f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c" , "notice" : "Some funds are pending confirmation and cannot be spent yet (Value 0.001 BTC)" }
将交易发送到同一交易中的多个收件人。
http:// localhost:3000 / merchant / $ guid / sendmany?password = $ main_password&second_password = $ second_password&recipients = $ recipients&fee = $ fee
响应:200 OK,应用程序/ json
{
"1JzSZFs2DQke2B3S4pBxaNaMzzVZaG4Cqh": 100000000,
"12Cf6nCcRtKERh9cQm3Z29c9MWvQuFSxvT": 1500000000,
"1dice6YgEVBf88erBFra9BHf6ZMoyvG88": 200000000
}
上面的示例会将1个BTC发送给1JzSZFs2DQke2B3S4pBxaNaMzzVZaG4Cqh,将15个BTC发送给12Cf6nCcRtKERh9cQm3Z29c9MWvQuFSxvT,将2个BTC发送给在同一事务中的交易1dice6YgEVBf88erBFra9BHf6ZMo。
响应:200 OK,应用程序/ json
{
"message" : "Response Message" , "tx_hash": "Transaction Hash" }
{
"message" : "Sent To Multiple Recipients" , "tx_hash" : "f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c" }
$guid="GUID_HERE";
$firstpassword="PASSWORD_HERE";
$secondpassword="PASSWORD_HERE";
$amounta = "10000000";
$amountb = "400000";
$addressa = "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq";
$addressb = "1ExD2je6UNxL5oSu6iPUhn9Ta7UrN8bjBy";
$recipients = urlencode('{
"'.$addressa.'": '.$amounta.',
"'.$addressb.'": '.$amountb.'
}');
$json_url = "http://localhost:3000/merchant/$guid/sendmany?password=$firstpassword&second_password=$secondpassword&recipients=$recipients";
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);
$message = $json_feed->message;
$txid = $json_feed->tx_hash;
?>
提取一个钱包的余额。这应仅用作估计,并且包括未确认的交易和可能的双花。
http:// localhost:3000 / merchant / $ guid / balance?password = $ main_password
响应:200 OK,应用程序/ json
{
"balance": Wallet Balance in Satoshi }
{
"balance": 1000}
列出钱包中的所有活动地址。还包括一个0确认余额,该余额仅应用作估算值,其中包括未确认的交易和可能的双倍支出。
http:// localhost:3000 / merchant / $ guid / list?password = $ main_password
响应:200 OK,应用程序/ json
{
"addresses": [
{
"balance": 1400938800,
"address": "1Q1AtvCyKhtveGm3187mgNRh5YcukUWjQC",
"label": "SMS Deposits",
"total_received": 5954572400
},
{
"balance": 79434360,
"address": "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq",
"label": "My Wallet",
"total_received": 453300048335
},
{
"balance": 0,
"address": "17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY",
"total_received": 0
}
]
}
检索比特币地址的余额。按标签查询地址余额已弃用。
http:// localhost:3000 / merchant / $ guid / address_balance?password = $ main_password&address = $ address
响应:200 OK,应用程序/ json
{
"balance" : Balance in Satoshi ,"address": "Bitcoin Address", "total_received" : Total Satoshi Received}
{
"balance" : 50000000, "address" : "19r7jAbPDtfTKQ9VJpvDzFFxCjUJFKesVZ", "total_received" : 100000000}
http:// localhost:3000 / merchant / $ guid / new_address?password = $ main_password&second_password = $ second_password&label = $ label
响应:200 OK,应用程序/ json
{
"address" : "The Bitcoin Address Generated" , "label" : "The Address Label"}
{
"address" : "18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy" , "label": "Order No : 1234" }
为了提高钱包性能,应将最近未使用过的地址移到存档状态。它们仍将保留在钱包中,但不再包含在“列表”或“列表事务”调用中。
例如,如果在付款后为用户生成了发票,则应将地址存档。
或者,如果为每个用户生成了唯一的比特币地址,则应将最近(〜30天)未登录其地址的用户存档。
http:// localhost:3000 / merchant / $ guid / archive_address?password = $ main_password&second_password = $ second_password&address = $ address
响应:200 OK,应用程序/ json
{
“ archived” :“ 18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy” }
取消存档地址。还将还原合并地址(请参见下文)。
http:// localhost:3000 / merchant / $ guid / unarchive_address?password = $ main_password&second_password = $ second_password&address = $ address
响应:200 OK,应用程序/ json
{
“ active” :“ 18fyqiZzndTxdVo7g9ouRogB4uFj86JJyy” }