eosjs
【eosjs】
Javascript API,用于帮助访问与 EOSIO RPC API.
1、安装
npm install eosjs@beta
2、Signature Provider
The Signature Provider holds private keys and is responsible for signing transactions.
const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // useraaaaaaaa
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
SignatureProvider是一个接口,不能直接使用。

JsSignatureProvider 实现了 SignatureProvider接口。是唯一实现了 SignatureProvider 接口的类。应当使用这个类。

JsSignatureProvider只两个方法:

3、JSON-RPC
Open a connection to JSON-RPC, include fetch when on NodeJS.
const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
JSON-RPC 实现了 AuthorityProvider、AbiProvider 两个Interface。



RPC 提供以下的方法:

4、API
实现了签名相关功能的类。
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
transact() is used to sign and push transactions onto the blockchain with an optional configuration object parameter.
通常使用 transaction 方法,发起一个交易:
(async () => {
const result = await api.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
to: 'useraaaaaaab',
quantity: '0.0001 SYS',
memo: '',
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.dir(result);
})();
transact是一个 async主法:

API 对象提供以下主法:

5、通常的使用流程。
使用 JsonRpc 对象、JsSignatureProvider 对象来创建一个 Api对象。
const { Api, JsonRpc } = require('eosjs');
const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); // development only
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextDecoder, TextEncoder } = require('text-encoding'); // node, IE11 and IE Edge Browsers
const privateKeys = [privateKey1];
const signatureProvider = new JsSignatureProvider(privateKeys);
const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
后续就使用 api.transact 来发起交易:
const result = await api.transact({
actions: [{
account: 'eosio',
name: 'buyrambytes',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
payer: 'useraaaaaaaa',
receiver: 'useraaaaaaaa',
bytes: 8192,
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
参考:
1、https://eosio.github.io/eosjs/
2、https://github.com/EOSIO/eosjs/tree/08b474e8c25ccccf2701ca04268fa5149728baa1
eosjs的更多相关文章
- eos TODO EOS区块链上EOSJS和scatter开发dApp
由于我一直在深入研究EOS dApp的开发,我看了不少好文章.在这里,我汇总了下做一些研究后得到的所有知识.在本文中,我将解释如何使用EOSJS和scatter.我假设你对智能合约以及如何在EOS区块 ...
- EOS开发实战
EOS开发实战 在上一篇文章<EOS开发入门>中,我们为大家介绍了EOS的节点启动和合约部署和调用等入门知识.本次我们来实现一个复杂的例子,可以为其取一个高大上的名字-悬赏任务管理系统 ...
- fibos开发踩坑集合
fibos.js API资料: 与eosjs相比,fibos.js没有添加新功能,可以在eosjs项目页面https://developers.eos.io/eosio-nodeos/referenc ...
- Setting up Scatter for Web Applications
[Setting up Scatter for Web Applications] If you are still using scatter-js please move over to scat ...
- 【精解】EOS TPS 多维实测
本文主要研究EOS的tps表现,会从插件.cleos.EOSBenchTool以及eosjs四种方式进行分析研究. 关键字:eos, tps, cleos, txn_test_gen_plugin, ...
- 【源码解读】EOS测试插件:txn_test_gen_plugin.cpp
本文内容本属于<[精解]EOS TPS 多维实测>的内容,但由于在编写时篇幅过长,所以我决定将这一部分单独成文撰写,以便于理解. 关键字:eos, txn_test_gen_plugin, ...
- 怎样使用EOS.JS的API
https://medium.com/coinmonks/how-to-use-eosjs-api-1-770b037b22ad https://blog.csdn.net/mongo_node/ar ...
- eos开发实践
一 下载前端代码 git clone https://github.com/baidang201/eos-todo 二 安装nodejs sudo apt-get install python-sof ...
- EOS源码分析:transaction的一生
最近在处理智能合约的事务上链问题,发现其中仍旧有知识盲点.原有的认识是一个事务请求会从客户端设备打包签名,然后通过RPC传到非出块节点,广播给超级节点,校验打包到可逆区块,共识确认最后变为不可逆区块. ...
随机推荐
- AJAX 请求后使用 JS 打开新标签页被阻止的解决方法
需求:发起一个 AJAX 请求,根据请求结果来打开一个新页面. 问题:AJAX 请求后,使用 window.open() 方法来打开新页面会被浏览器阻止. 解决方法:在 AJAX 请求之前,就使用 c ...
- How to Create an PostgreSQL Extension
转自:https://severalnines.com/blog/creating-new-modules-using-postgresql-create-extension Extensibilit ...
- python base64.b64decode 等号可以随便加
由于 = 用在URL,cookie里会造成歧义,所以base64编码的时候,会把 = 自动去掉. 解码的时候,如果传入的二进制编码长度小于4的倍数,那么需要在后面补=,知道满足长度等于4的倍数,然后 ...
- CMake for MFC example
cmake_minimum_required(VERSION 2.8) add_definitions(-D_AFXDLL) set(CMAKE_MFC_FLAG 2) set(SRCS MFCApp ...
- kindle試玩
Q:試玩感受如何? Pros 按這個版本,沒有燈,在光纖不好的時候看起來很累.但陽光好的時候看起來很爽 重量很輕,比手機邀請很多 看書很容易沉浸下去,這一點比收集好狠毒 Cons 網上說看pdf不大行 ...
- python 常用的模块
面试的过程中经常被问到使用过那些python模块,然后我大脑就出现了一片空白各种模块一顿说,其实一点顺序也没有然后给面试官造成的印象就是自己是否真实的用到这些模块,所以总结下自己实际工作中常用的模块: ...
- css 样式控制文本过长实现省略号
css 样式控制文本过长实现省略号 .topicTitle{ text-overflow: ellipsis; max-width: 75%; overflow: hidden; white-spac ...
- sql 不够七位数 在左侧自动补零 ,并循环插入N条记录
select right(cast('0000000000'+rtrim(字段) as varchar(20)),7) declare @i intdeclare @qid int set @i=1s ...
- SpringCloud和Springboot
SpringBoot+SpringCloud+SpringMVC+SpringData 我们把这种架构也称之为spring全家桶 什么是SpringCloudSpring Cloud是一系列框架的有序 ...
- CRM 模拟用户
web api 模拟用户 转:https://blog.csdn.net/vic0228/article/details/80649615 var req = new XMLHttpRequest() ...