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传到非出块节点,广播给超级节点,校验打包到可逆区块,共识确认最后变为不可逆区块. ...
随机推荐
- 《从Lucene到Elasticsearch:全文检索实战》学习笔记五
今天我给大家讲讲tf-idf权重计算 tf-idf权重计算: tf-idf(中文词频-逆文档概率)是表示计算词项对于一个文档集或语料库中的一份文件的重要程度.词项的重要性随着它在文档中出现的次数成正比 ...
- macbook 下 spark开发环境搭建(基于idea 和maven)及spark单机写运行jar
参见链接 https://blog.csdn.net/u012373815/article/details/53266301 运行jar包: 将写好的项目打成jar,上传到服务器,进入SPARK_HO ...
- vue中使用axios给生产环境和开发环境配置不同的baseUrl
第一步:设置不同的接口地址 找到文件:/config/dev.env.js 代码修改为: var merge = require('webpack-merge') var prodEnv = requ ...
- 1_2_3_4_5 Html-Css
--------------------------------------------------------------------------------- HTML骨架 <HTML> ...
- kafka-producer partitioner.class的使用
partitioner.class的说明 在API客户端中封装好的partition( )方法会为消息选择一个分区编号.为了保证消息负载均衡到每个分区,可以通过使用默认方式或者 手动配置这个参数的 ...
- 创建一个dynamics 365 CRM online plugin (二) - fields检查
Golden Rules 1. Platform only passes Entity attributes to Plugin that has change of data. 2. If the ...
- live555 交叉编译移植到海思开发板
本文章参考了.http://blog.csdn.net/lawishere/article/details/8182952,写了hi3518的配置说明.特此感谢 https://blog.csdn.n ...
- eclipse开启时报错问题
eclipse启动时报如下错误: Unable to read workbench state.Workbench UI layout will be reset 不能找到正式的工作台,工作台UI的布 ...
- MySQL Point in Time Recovery the Right Way
In this blog, I’ll look at how to do MySQL point in time recovery (PITR) correctly. Sometimes we nee ...
- vagrant up报错 Warning: Authentication failure. Retrying...解决方案
参照链接 https://www.cnblogs.com/zqifa/p/vagrant-1.html 可以解决问题.