对接Ripple(XRP),不需要本地部署钱包,直接访问Ripple API,本文包括访问Ripple API及如何免费获取测试的XRP。
对接流程
- 安装Ripple API
- Ripple API 接口说明
- 免费获取测试的XRP
Ripple API GitHub地址:https://github.com/ripple/ripple-lib/
需要的环境:NodeJS
安装命令:yarn add ripple-lib 或 npm install ripple-lib
引用Ripple API:const RippleAPI = require('ripple-lib').RippleAPI;
实例化Ripple API:api = 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的钱包对接过程!
BIZZAN(币严) 数字货币交易所官方网址:
【[转载][币严区块链]数字货币交易所之瑞波(XRP)钱包对接】www.bizzan.com
推荐阅读
- 推动NFT走出监管困境,BSN推出支持NFT基础设施网络
- 腾讯|SaaS的收入模型有哪些(终于有人讲明白了)
- 就业方向上什么才是最重要的(--- 来自程序猿的迷茫。(C++?Java?or算法?))
- 区块链中加密货币的含义
- 波场万倍潜力币HYL23号21:09分 正式上线JustSwap
- 《瀚兰房地产开发区块链应用及案例分享》BSN培训精华回顾
- 对联盟链而言,跨链协议为什么重要()
- 区块链能够应用在哪些行业
- BSN区块链服务网络中密钥托管模式和公钥上传模式有啥区别()
- 币圈人物传|币圈大佬今何在 唯有一诺正当时