[[toc]]
- 正常情况下,所有实例使用的 node.js 为最新的 LTS 版本
- 正常情况下,所有显式安装的包使用缺省的最新版本
- 正常情况下,我们使用脚本方式运行
- 用 npm 安装
$ npm install @swtc/lib- 浏览器直接引用
- CDN 直接引用
<script src='https://unpkg.com/@swtc/lib'></script>- 或者
<script src='https://cdn.jsdelivr.net/npm/@swtc/lib'></script>
- 可以 自行编译
- 不建议使用此方式
- 建议使用 webpack 打包 方式替代
- CDN 直接引用
- 常规导入
const Wallet = require("@swtc/lib").Wallet
const Remote = require("@swtc/lib").Remote- 导入钱包/库
const Remote = require('@swtc/lib').Remoteimport { Remote } from '@swtc/lib'
- 创建 remote 对象
const remote = new (require('@swtc/lib').Remote)()
const remote_test = new (require('@swtc/lib').Remote)({server: 'ws://ts5.jingtum.com:5030', issuer: 'jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS'})2. 连接服务器remote.connectPromise().then(console.log).catch(console.error)3. 获取帐本remote.requestLedgerClosed().submitPromise().then(console.log)4. 获取交易remote.requestTx({hash: 'hash'}).submitPromise().then(console.log)5. 获取帐号信息remote.requestAccountInfo({account: 'address'}).submitPromise().then(console.log)6. 获得账号可接收和发送的货币remote.requestAccountTums({account: 'address'}).submitPromise().then(console.log)7. 支付remote.buildPaymentTx({source: 'address1', to: 'address2', amount: remote.makeAmount(1)}).submitPromise('secret', 'memo').then(console.log)8. 挂单remote.buildOfferCreateTx({type: 'Sell', account: 'address', taker_gets: remote.makeAmount(1), taker_pays: remote.makeAmount(0.01, 'cnt')}).submitPromise('secret', 'memo').then(console.log).catch(console.error)9. 查询挂单remote.requestAccountOffers({account: DATA.address}).submitPromise().then(console.log)10. 撤单remote.buildOfferCancelTx({ account: 'address', sequence: offerSequence}).submitPromise('secret', 'memo').then(console.log)11. 获取信任remote.requestAccountRelations({type: 'trust', account: 'address'}).submitPromise().then(console.log)12. 获取授权remote.requestAccountRelations({type: 'authorize', account: 'address'}).submitPromise().then(console.log)13. 设置信任remote.buildRelationTx({type: 'trust', account: 'address', target; 'issuer', limit: remote.makeAmount(10000, 'CNY')}).submitPromise('secret', 'memo').then(console.log)14. 设置授权remote.buildRelationTx({type: 'authorize', account: 'address', target; 'address2', limit: remote.makeAmunt(1000, 'CNY')}).submitPromise('secret', 'memo').then(console.log)15. 获得市场挂单列表remote.requestOrderBook({gets: remote.makeCurrency(), pays: remote.makeCurrency('cnt')}).submitPromise().then(console.log).catch(console.error)
- 展示 wallet 的创建
- 展示最新的帐本信息
- 查询价格
- [-] 查询余额
- [-] 赞助支付
- node.js 运行时环境
- 常运行于服务器
- 常运行于终端中
- 浏览器运行时环境
- 常运行于客户端
- 常运行于浏览器中
- W00 相关说明
- W01 浏览器终端示例
- W02 常规 WEB 示例
- W03 打包 WEB 示例
- W04 React Web 示例
- W05 Vue Web 示例
- W06 Angular Web 示例
- W07 weex Web 示例
- W08 nuxt 示例
- 通常浏览器运行时环境
- 通常将 web 应用打包成桌面应用
- 通常跨平台兼容
- 通常翻译成移动设备自身运行时环境
- react native | Facebook
- flutter | Google
- nativescript | Telerik
- weex | Apache
- M00 相关说明
- Nativescript 示例
- M02 Nativescript Vue 示例
- Nativescript Angular 示例
- React Native 示例
- Flutter 示例
- Weex 示例