Gathering detailed insights and metrics for enf-eosjs
Gathering detailed insights and metrics for enf-eosjs
Gathering detailed insights and metrics for enf-eosjs
Gathering detailed insights and metrics for enf-eosjs
Official Javascript Library for Working with EOS Blockchain
npm install enf-eosjs
Typescript
Module System
Node Version
NPM Version
60
Supply Chain
98.2
Quality
74.1
Maintenance
50
Vulnerability
100
License
TypeScript (83.54%)
JavaScript (11.48%)
HTML (3.51%)
Shell (0.82%)
CSS (0.52%)
C++ (0.13%)
Total Downloads
2,842
Last Day
1
Last Week
6
Last Month
64
Last Year
918
22 Stars
465 Commits
6 Forks
17 Watching
6 Branches
44 Contributors
Minified
Minified + Gzipped
Latest Version
23.0.0
Package Id
enf-eosjs@23.0.0
Unpacked Size
333.18 kB
Size
68.50 kB
File Count
58
NPM Version
9.4.2
Node Version
18.13.0
Publised On
07 Jun 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-76%
6
Compared to previous week
Last month
-62.4%
64
Compared to previous month
Last year
-23.6%
918
Compared to previous year
4
24
enf-eosjs
Javascript API for integration with EOS-based blockchains.
enf-eosjs has been updated to support latest features in EOS blockchain. This is an updated version of the popular eosjs package.
npm install enf-eosjs
If you're using Node (not a browser) then you'll also need to make sure the dom
lib is referenced in your tsconfig.json
:
{
"compilerOptions": {
"lib": [..., "dom"]
}
}
Clone this repository locally then run npm run build-web
. The browser distribution will be located in dist-web
and can be directly copied into your project repository. The dist-web
folder contains minified bundles ready for production, along with source mapped versions of the library for debugging.
Very simple example of using enf-eosjs. Included unused imports as examples.
1npm init es6 2npm install enf-eosjs 3node node_test
1/* 2 * @module test_enf_eosjs 3 * PUT THIS INTO A FILE NAMED node_test.js 4 */ 5 6import { Api, JsonRpc, RpcError } from 'enf-eosjs'; 7import fetch from 'node-fetch' 8 9const rpc = new JsonRpc('https://localhost:443', { fetch }); 10const api = new Api({ rpc, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); 11 12var info = await rpc.get_info(); 13 14console.log(info);
It best to use a secure well supported secret store. Some examples of providers include:
JsSignatureProvider is included as an example, and it is not provided by enf-eosjs.
Importing using ES6 module syntax in the browser is supported if you have a transpiler, such as Babel.
1import { Api, JsonRpc, RpcError } from 'enf-eosjs'; 2import { JsSignatureProvider } from 'enf-eosjs/dist/eosjs-jssig'; // development only
Importing using commonJS syntax is supported by NodeJS out of the box.
1const { Api, JsonRpc, RpcError } = require('enf-eosjs'); 2const fetch = require('node-fetch'); // node only; not needed in browsers
The Signature Provider holds private keys and is responsible for signing transactions.
Using the JsSignatureProvider in the browser is not secure and should only be used for development purposes. Use a secure vault outside of the context of the webpage to ensure security when signing transactions in production
1const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // bob 2const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
Open a connection to JSON-RPC, include fetch
when on NodeJS.
1const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
No longer need to include textDecoder and textEncoder when using in Node, React Native, IE11 or Edge Browsers.
1const 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. This parameter can override the default value of broadcast: true
, and can be used to fill TAPOS fields given blocksBehind
and expireSeconds
. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (expiration
, ref_block_num
, ref_block_prefix
) and will automatically be broadcast onto the chain.
With the introduction of Leap v3.1 the retry transaction feature also adds 5 new optional fields to the configuration object:
useOldRPC
: use old RPC push_transaction
, rather than new RPC send_transactionuseOldSendRPC
: use old RPC /v1/chain/send_transaction
, rather than new RPC /v1/chain/send_transaction2
returnFailureTrace
: return partial traces on failed transactionsretryTrxNumBlocks
: request node to retry transaction until in a block of given height, blocking callretryIrreversible
: request node to retry transaction until it is irreversible or expires, blocking call1(async () => { 2 const result = await api.transact({ 3 actions: [{ 4 account: 'eosio.token', 5 name: 'transfer', 6 authorization: [{ 7 actor: 'useraaaaaaaa', 8 permission: 'active', 9 }], 10 data: { 11 from: 'useraaaaaaaa', 12 to: 'useraaaaaaab', 13 quantity: '0.0001 SYS', 14 memo: '', 15 }, 16 }] 17 }, { 18 blocksBehind: 3, 19 expireSeconds: 30 20 }); 21 console.dir(result); 22})();
Leap 4.0 introduced read only transaction. A read-only transaction does not change the state and is not added into the blockchain. It is useful for users to retrieve complex chain information.
1/* 2 * Read Only transaciton can not modify state 3 * In this example a special read only action in a custom contract is executed 4 * Note the empty fields for authoriziation and data. 5 */ 6const readonlyTransfer = async () => 7 await api.transact( 8 { 9 actions: [ 10 { 11 account: testActor, 12 name: 'getvalue', 13 authorization: [], 14 data: {}, 15 }, 16 ], 17 }, 18 { 19 broadcast: true, 20 readOnly: true, 21 blocksBehind: 3, 22 expireSeconds: 72, 23 } 24 ) 25// execute the read only transaction 26const transactionReadOnlyResponse = await readonlyTransfer(); 27// processed.receipt has status,cpu_usage_us,net_usage_words 28console.log(`Transaction Id ${transactionReadOnlyResponse.transaction_id} CPU Usage ${transactionReadOnlyResponse.processed.receipt.cpu_usage_us}`)
use RpcError
for handling RPC Errors
1... 2try { 3 const result = await api.transact({ 4 ... 5} catch (e) { 6 console.log('\nCaught exception: ' + e); 7 if (e instanceof RpcError) 8 console.log(JSON.stringify(e.json, null, 2)); 9} 10...
See LICENSE for copyright and license terms. This work is made on a voluntary basis as a member of the EOSIO community and is not responsible for ensuring the overall performance of the software or any related applications. We make no representation, warranty, guarantee or undertaking in respect of the software or any related documentation, whether expressed or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall we be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or documentation or the use or other dealings in the software or documentation. Any test results or performance figures are indicative and will not reflect performance under all conditions. Any reference to any third party or third-party product, service or other resource is not an endorsement or recommendation by Block.one. We are not responsible, and disclaim any and all responsibility and liability, for your use of or reliance on any of these resources. Third-party resources may be updated, changed or terminated at any time, so the information here may be out of date or inaccurate. Any person using or offering this software in connection with providing software, goods or services to third parties shall advise such third parties of these license terms, disclaimers and exclusions of liability. Block.one, EOSIO, EOSIO Labs, EOS, EOS Network Foundation.
Wallets and related components are complex software that require the highest levels of security. If incorrectly built or used, they may compromise users’ private keys and digital assets. Wallet applications and related components should undergo thorough security evaluations before being used. Only experienced developers should work with this software.
No vulnerabilities found.
No security vulnerabilities found.