首页 文章 精选 留言 我的

精选列表

搜索[javascript引擎],共10000篇文章
优秀的个人博客,低调大师

用JavaScript开发Stellar区块链应用

Stellar JS SDK封装了Stellar交易的提交,以及与Stellar Horizon API服务器的交互过程,可以运行在Node.js环境或Web浏览器中。js-stellar-sdk主要有两个作用:1、通过HorizonAPI服务器查询Stellar区块链数据 2、构建Stellar交易、签名并提交到Stellar网络中。 相关推荐:汇智网 区块链开发系列教程 1、构造Horizon访问请求 js-stellar-sdk使用Builder模式来创建要发送给Horizon API服务器的请求。从一个server对象开始,你可以通过链式调用来生成最终的查询请求。例如: var StellarSdk = require('stellar-sdk'); var server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); // get a list of transactions that occurred in ledger 1400 server.transactions() .forLedger(1400) .call().then(function(r){ console.log(r); }); // get a list of transactions submitted by a particular account server.transactions() .forAccount('GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW') .call().then(function(r){ console.log(r); }); 一旦请求构造好了,就可以调用.call()或.stream()来提交请求。.call()将返回一个promise对象,其解析结果为Horizon服务器的响应。 2、发送流式请求 许多请求可以使用.stream()来调用。与.call()返回promise对象不同,.stream()将返回一个EventSource对象。Horizon API服务器会自动推送相关的数据给请求的客户端。 例如,下面的代码显示输出指定的Stellar账户的交易: var StellarSdk = require('stellar-sdk') var server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); var lastCursor=0; // or load where you left off var txHandler = function (txResponse) { console.log(txResponse); }; var es = server.transactions() .forAccount(accountAddress) .cursor(lastCursor) .stream({ onmessage: txHandler }) 3、处理Stellar Horizon API服务器的响应 3.1 Stellar XDR格式解码 Horizon API服务器的交易访问端结点会以原始XDR格式返回某些字段。你可以使用.fromXDR()将XDR转换为JSON格式。 例如,下面的代码重写了上面示例中的txHandler来将XDR字段显示为JSON格式: var txHandler = function (txResponse) { console.log( JSON.stringify(StellarSdk.xdr.TransactionEnvelope.fromXDR(txResponse.envelope_xdr, 'base64')) ); console.log( JSON.stringify(StellarSdk.xdr.TransactionResult.fromXDR(txResponse.result_xdr, 'base64')) ); console.log( JSON.stringify(StellarSdk.xdr.TransactionMeta.fromXDR(txResponse.result_meta_xdr, 'base64')) ); }; 3.2 Horizon响应结果中的链接跟随 在Horizon响应中包含的链接已经被转换为对应的方法调用,这让你可以简单地通过.next()方法来逐页查看结果,同时也让获取额外信息更加轻松。例如: server.payments() .limit(1) .call() .then(function(response){ // will follow the transactions link returned by Horizon response.records[0].transaction().then(function(txs){ console.log(txs); }); }); 4、Stellar交易构建与广播 4.1 Stellar交易构建 Stellar的交易构建过程稍微复杂一点,我们将在另一篇文章中介绍,你可以先查看英文原文 4.2 Stellar交易提交 一旦创建好了交易,就可以使用Server.submitTransaction()方法将其提交到Stellar网络中。 const StellarSdk = require('stellar-sdk') StellarSdk.Network.useTestNetwork(); const server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); (async function main() { const account = await server.loadAccount(publicKey); /* Right now, we have one function that fetches the base fee. In the future, we'll have functions that are smarter about suggesting fees, e.g.: `fetchCheapFee`, `fetchAverageFee`, `fetchPriorityFee`, etc. */ const fee = await server.fetchBaseFee(); const transaction = new StellarSdk.TransactionBuilder(account, { fee }) .addOperation( // this operation funds the new account with XLM StellarSdk.Operation.payment({ destination: "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", asset: StellarSdk.Asset.native(), amount: "20000000" }) ) .setTimeout(30) .build(); // sign the transaction transaction.sign(StellarSdk.Keypair.fromSecret(secretString)); try { const transactionResult = await server.submitTransaction(transaction); console.log(transactionResult); } catch (err) { console.error(err); } })() 原文链接:Stellar JS SDK简明教程 - 汇智网

优秀的个人博客,低调大师

原生javascript中的的AJAX写法

js中ajax get请求的写法 var xhr=new XMLHttpRequest(); xhr.open('get','请求地址') xhr.send(); xhr.onreadystatechange=function () { if (xhr.readyState==4) { // console.log(xhr.responeText } } js中post请求的写法 var xhr = new XMLHttpRequest(); xhr.open('post',"请求地址",true); // 如果是post请求 必须加上请求头 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xhr.send("userName="+user.value+'&passWord='+pass.value); xhr.onreadystatechange =function(){ if (xhr.readyState==4) { var obj = JSON.parse(xhr.responseText); console.log(obj.responseCode); if (obj.responseCode=="0") { window.location.href = "denglu.html" } } }

优秀的个人博客,低调大师

Riot 4.6.0 发布,JavaScript 的 MVP 框架

Riot 4.6.0 发布了,更新内容如下: 修复了在<template>标签中呈现文本表达式的情况下的小写问题 更新改进了核心代码、编译器和 dom 绑定 通过<slot>属性添加对 HOC(高阶组件)组件的支持,例如: Provider <hoc-component> <slot message={ message } theme={ theme }/> <script> export default { message: 'hello', theme: 'dark' } </script> </hoc-component> Consumer <app> <hoc-component> <!-- the {message} property will be provided by the <hoc-component> --> <h1>{ message }</h1> <!-- the {theme} property will be provided by the <hoc-component> --> <sidebar theme={ theme }/> </hoc-component> <!-- the {message} property is not available outside of the <hoc-component> --> <p>{ message }</p> </app> Riot 是一个简单而优雅的基于组件的 UI 库,为所有现代浏览器带来了自定义组件。其支持浏览器包括: 它的体积也很小,只有 6k:

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册