eosjs | General purpose library for the EOSIO blockchain | Blockchain library
kandi X-RAY | eosjs Summary
kandi X-RAY | eosjs Summary
Javascript API for integration with EOSIO-based blockchains using EOSIO RPC API.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of eosjs
eosjs Key Features
eosjs Examples and Code Snippets
Community Discussions
Trending Discussions on eosjs
QUESTION
I'm trying to deploy an EOS Smart Contract using eosjs
.
I referred the code from https://eosio.github.io/eosjs/latest/how-to-guides/how-to-deploy-a-smart-contract
ANSWER
Answered 2019-Dec-23 at 06:40 const wasmFilePath = './hello.wasm'
const abiFilePath = './hello.abi'
const fs = require('fs')
const { Api, JsonRpc, Serialize } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
const fetch = require('node-fetch'); //node only
const { TextDecoder, TextEncoder } = require('util'); //node only
let privateKey1 = '5J***********'
const privateKeys = [privateKey1];
const signatureProvider = new JsSignatureProvider(privateKeys);
const rpc = new JsonRpc('https://jungle2.cryptolions.io:443', { fetch }); //required to read blockchain state
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const wasmHexString = fs.readFileSync(wasmFilePath).toString('hex')
const buffer = new Serialize.SerialBuffer({
textEncoder: api.textEncoder,
textDecoder: api.textDecoder,
})
let abiJSON = JSON.parse(fs.readFileSync(abiFilePath, 'utf8'))
const abiDefinitions = api.abiTypes.get('abi_def')
abiJSON = abiDefinitions.fields.reduce(
(acc, { name: fieldName }) =>
Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
abiJSON
)
abiDefinitions.serialize(buffer, abiJSON)
let serializedAbiHexString = Buffer.from(buffer.asUint8Array()).toString('hex')
deployContract();
async function deployContract(){
try{
const wasmFilePath = './hello.wasm'
const abiFilePath = './hello.abi'
const fs = require('fs')
const { Api, JsonRpc, Serialize } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
const fetch = require('node-fetch'); //node only
const { TextDecoder, TextEncoder } = require('util'); //node only
let privateKey1 = '5J***********'
const privateKeys = [privateKey1];
const signatureProvider = new JsSignatureProvider(privateKeys);
const rpc = new JsonRpc('https://jungle2.cryptolions.io:443', { fetch }); //required to read blockchain state
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const wasmHexString = fs.readFileSync(wasmFilePath).toString('hex')
const buffer = new Serialize.SerialBuffer({
textEncoder: api.textEncoder,
textDecoder: api.textDecoder,
})
let abiJSON = JSON.parse(fs.readFileSync(abiFilePath, 'utf8'))
const abiDefinitions = api.abiTypes.get('abi_def')
abiJSON = abiDefinitions.fields.reduce(
(acc, { name: fieldName }) =>
Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
abiJSON
)
abiDefinitions.serialize(buffer, abiJSON)
let serializedAbiHexString = Buffer.from(buffer.asUint8Array()).toString('hex')
deployContract();
async function deployContract(){
try{
await api.transact(
{
actions: [
{
account: 'eosio',
name: 'setcode',
authorization: [
{
actor: user_name,
permission: 'active',
},
],
data: {
account: user_name,
vmtype: '0',
vmversion: '0',
code: wasmHexString,
},
},
{
account: 'eosio',
name: 'setabi',
authorization: [
{
actor: user_name,
permission: 'active',
},
],
data: {
account: user_name,
abi: serializedAbiHexString,
},
},
],
},
{
blocksBehind: 3,
expireSeconds: 30,
}
)
}
catch(e){
console.log(e)
}
};
};
QUESTION
I have a require statement like this
...ANSWER
Answered 2019-Mar-19 at 03:52IIRC you don't need the unwanted items at all - since objects are used with keys (property names), you can only get the ones you want:
QUESTION
I have a lerna project which contains two identical packages (named p1 and p2)
Both p1 and p2 include a 3rd party package – for this test I’ve used eosjs@beta, which is about 50KB
If I then create an example react project and include P1, the package size grows by 50KB as expected, but what’s surprising me is that when I add p2 … it grows by another 50KB.
One would think that because p1 and p2 are using the same 3rd party library, that one reference to that library would be compiled into the example project. But that’s not what seems to happen.
Example repo here: https://github.com/warrick-eosny/sizetest
The growth of the package looks as follows:
ls examples/sizetest/build/static/js/ -lah
Before I reference p1
...ANSWER
Answered 2019-Feb-10 at 00:59Neither a monorepo as a concept nor Lerna as a tool are meant to do such kind of implicit "improvements". This may have unwanted side effects (for example if P1 and P2 depend on different versions of eosjs
or where each package initiates an own instance of some package class).
Another reason speaking against doing what you are expecting here, is that packages in a monorepo still can be deployed independently from each other because they don't rely on the same reference of a package.
Utilizing a monorepo is as far as I know the only way to achieve what you are looking for. However, the monorepo just manages your codebase in one place. If you want to use the same reference of eosjs
in both your packages, move it up into the root level package.json
, but then you will also have to deal with a bunch of other problems that you might not expect yet. You can do it manually for your self-maintained monorepo packages or by hoisting for external packages with Lerna: https://github.com/lerna/lerna/blob/master/doc/hoist.md
Yarn Workspaces is what Lerna uses under the hood to achieve hoisting and might also help for understanding.
Webpack doesn't know about being in a monorepo unless you told it somehow, too. Its working independently of Lerna or monorepos.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install eosjs
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page