区块链钱包API(用于区块链钱包用户发送和接收比特币付款的简单API)

区块链钱包API提供了一个简单的界面,商家可以使用该界面以编程方式与其钱包进行交互。

安装

使用此API,将需要运行小型本地服务,该服务负责管理您的Blockchain Wallet。应用程序通过HTTP API调用在本地与该服务进行交互。获取有关GitHub的完整设置说明:https://github.com/blockchain/service-my-wallet-v3

创建钱包API,以编程方式创建区块链钱包

create_wallet方法可用于创建新的blockchain.info比特币钱包。

网址: http:// localhost:3000 / api / v2 / create
方法: POST或GET

  • $ password新钱包的密码。长度至少必须为10个字符。
  • $ api_code具有创建钱包权限的API代码。
  • $ priv 要添加到钱包的私钥(首选钱包导入格式)。(可选的)
  • $ label 为钱包中的第一个地址设置的标​​签。仅字母数字。(可选的)
  • $ email 与新钱包相关联的电子邮件,即您代表其创建该钱包的用户的电子邮件地址。(可选的)

响应: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

  • $ main_password您的主区块链钱包密码
  • $ second_password如果启用了双重加密,则是您的第二个Blockchain Wallet密码。
  • $至收件人比特币地址。
  • $ amount发送聪的金额。
  • $ from 从特定的比特币地址发送(可选)
  • satfe中的$ 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

扫描二维码关注公众号,回复: 11300478 查看本文章
  • $ main_password您的主要区块链钱包密码
  • $ second_password如果启用了双重加密,则是您的第二个Blockchain Wallet密码。
  • $ recipients是一个JSON对象,使用比特币地址作为键,并将要发送的金额作为值。
  • $ from 从特定的比特币地址发送(可选)
  • satfe中的$ 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" }

PHP示例

<?

$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

  • $ main_password您的主要区块链钱包密码
  • $ 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

  • $ main_password您的主要区块链钱包密码
  • $ second_password如果启用了双重加密,则是您的第二个Blockchain Wallet密码。
  • $ label附加到此地址的可选标签。建议使用人类可读的字符串,例如“ Order
    No:1234”。您可以以此为参考来检查订单余额(稍后记录)

响应: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

  • $ main_password您的主要区块链钱包密码
  • $ address要存档的比特币地址

响应:200 OK,应用程序/ json

{ “ archived” :“ 18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy” }  

取消存档地址

取消存档地址。还将还原合并地址(请参见下文)。

http:// localhost:3000 / merchant / $ guid / unarchive_address?password = $ main_password&second_password = $ second_password&address = $ address

  • $ main_password您的主要区块链钱包密码
  • $ address要取消存档的比特币地址

响应:200 OK,应用程序/ json

{ “ active” :“ 18fyqiZzndTxdVo7g9ouRogB4uFj86JJyy” }  

猜你喜欢

转载自blog.csdn.net/weixin_42224055/article/details/105858016
今日推荐