[币严区块链]数字货币交易所之瑞波(XRP)钱包对接

对接Ripple(XRP),不需要本地部署钱包,直接访问Ripple API,本文包括访问Ripple API及如何免费获取测试的XRP。

对接流程

  1. 安装Ripple API
  2. Ripple API 接口说明
  3. 免费获取测试的XRP

一、安装Ripple API

Ripple API GitHub地址https://github.com/ripple/ripple-lib/

需要的环境NodeJS

安装命令yarn add ripple-libnpm install ripple-lib

引用Ripple APIconst RippleAPI = require('ripple-lib').RippleAPI;

实例化Ripple APIapi = new RippleAPI({server:host});

Host 测试网络地址wss://s.altnet.rippletest.net:51233

Host 主网地址wss://s2.ripple.com

二、Ripple API 接口说明

Ripple API 说明文档:https://github.com/ripple/ripple-lib/blob/develop/docs/index.md

需要的API方法:

  • connect:连接到ripple 服务器
api.connect().then(() => {}).catch(console.error);
  • getFee:获取交易手续费
api.getFee().then(fee => {console.log(fee)});
  • getBalances:获取账户余额信息
api.getBalances(address).then(balances =>{console.log(balances)});
  • generateAddress:生成地址及私钥方法
api.generateAddress();
  • getTransactions:获取账户交易记录列表
api.getTransactions(address).then(transactions => {console.log(transactions)});
  • getTransaction:获取交易记录信息
api.getTransaction(txid).then(transaction => {console.log(transaction)});
  • preparePayment:创建未签名的交易信息
const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';
const payment = {
  "source": {
    "address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "maxAmount": {
      "value": "0.01",
      "currency": "XRP"
    }
  },
  "destination": {
    "address": "rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo",
    "amount": {
      "value": "0.01",
      "currency": " XRP "
    }
  }
};
return api.preparePayment(address, payment).then(prepared =>
  {console.log(prepared)});
  • sign:签名交易信息
const txJSON = '{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"726970706C652E636F6D","LastLedgerSequence":8820051,"Fee":"12","Sequence":23}';
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV';
return api.sign(txJSON, secret);
  • submit:广播发送交易
const signedTransaction = '12000322800000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100BDE09A1F6670403F341C21A77CF35BA47E45CDE974096E1AA5FC39811D8269E702203D60291B9A27F1DCABA9CF5DED307B4F23223E0B6F156991DB601DFB9C41CE1C770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304';
return api.submit(signedTransaction)
  .then(result => {console.log(result)});
Result:
{
  "resultCode": "tesSUCCESS",
  "resultMessage": "The transaction was applied. Only final in a validated ledger."
}

三、免费获取测试的XRP

访问Ripple Testnet 水龙头网站:https://developers.ripple.com/xrp-test-net-faucet.html

点击 Generate credentials 按钮,就会得到一个Ripple账户,包含地址及私钥,另外这个账户中将有10000个测试的XRP

 

 以上就是瑞波XRP的钱包对接过程!

转载自:https://blog.csdn.net/wudwolf/article/details/82987911

本文对原文进行了排版以增加易读性!

猜你喜欢

转载自www.cnblogs.com/bizzan/p/10402802.html