1655494920
Allows you to interact with the Zilliqa network nodes.
zilliqa-js
is structured as a Lerna monorepo. Each package roughly corresponds to a discrete ZilliqaModule
, most of which can be used independently.
The only required package is @zilliqa-js/core
, which contains the default HTTPProvider
, and other core abstractions that are necessary for other modules to function.
The following table provides a description of each module and what you may want to use it for.
Package | Version | Description | Dependencies |
---|---|---|---|
@zilliqa-js/core | Core abstractions and base classes, such as HTTPProvider and network logic for interfacing with the Zilliqa JSON-RPC. | ||
@zilliqa-js/util | Miscellaneous functions that take care of serialisation/deserialisation and validation. | ||
@zilliqa-js/crypto | Exposes several loosely-coupled cryptographic convenience functions for working with the Zilliqa blockchain and its cryptographic primitives, such as Schnorr signatures. | @zilliqa-js/util | |
@zilliqa-js/proto | Protobuf source files and corresponding generated JS modules. | ||
@zilliqa-js/account | Wallet , Account and Transaction abstractions. | @zilliqa-js/core , @zilliqa-js/crypto , @zilliqa-js/proto | |
@zilliqa-js/blockchain | Main interface to the Zilliqa JSON-RPC . | @zilliqa-js/account | |
@zilliqa-js/contract | Exposes a Contracts module that takes care of smart contract deployment and interaction. | @zilliqa-js/blockchain | |
@zilliqa-js/subscriptions | Classes to interact with the websocket API of Zilliqa node. | ||
@zilliqa-js/scilla-json-utils | Simplifies the way you construct the Scilla JSON data. | ||
@zilliqa-js/viewblock | Library interfacing with ViewBlock's APIs. This package is maintained by Ashlar | @zilliqa-js/crypto |
zilliqa-js
uses scrypt
library which depends on node-gyp
in order to compile the binaries from source on Windows. node-gyp
on Windows requires users to install additional Visual Studio Build tools.
To install the required Visual Studio Build tools:
npm install --global --production windows-build-tools # from an elevated PowerShell or CMD.exe as Administrator
npm config set msvs_version 2015 # 2015 is more compatible; though 2017 may work too
Refer to https://github.com/nodejs/node-gyp#installation for more information about node-gyp
installation on Windows.
It is recommended that developers install the JavaScript client by making use of the umbrella package @zilliqa-js/zilliqa
. This takes care of bootstrapping the various modules, which are then accessible as members of the Zilliqa
class.
npm i @zilliqa-js/zilliqa
# or
yarn add @zilliqa-js/zilliqa
You can create a test account by using Zilliqa Dev Wallet and request funds by using ZIL Faucet service.
const { BN, Long, bytes, units } = require('@zilliqa-js/util');
const { Zilliqa } = require('@zilliqa-js/zilliqa');
const {
toBech32Address,
getAddressFromPrivateKey,
} = require('@zilliqa-js/crypto');
const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
// These are set by the core protocol, and may vary per-chain.
// You can manually pack the bytes according to chain id and msg version.
// For more information: https://apidocs.zilliqa.com/?shell#getnetworkid
const chainId = 333; // chainId of the developer testnet
const msgVersion = 1; // current msgVersion
const VERSION = bytes.pack(chainId, msgVersion);
// Populate the wallet with an account
const privateKey =
'3375F915F3F9AE35E6B301B7670F53AD1A5BE15D8221EC7FD5E503F21D3450C8';
zilliqa.wallet.addByPrivateKey(privateKey);
const address = getAddressFromPrivateKey(privateKey);
console.log(`My account address is: ${address}`);
console.log(`My account bech32 address is: ${toBech32Address(address)}`);
async function testBlockchain() {
try {
// Get Balance
const balance = await zilliqa.blockchain.getBalance(address);
// Get Minimum Gas Price from blockchain
const minGasPrice = await zilliqa.blockchain.getMinimumGasPrice();
// Account balance (See note 1)
console.log(`Your account balance is:`);
console.log(balance.result);
console.log(`Current Minimum Gas Price: ${minGasPrice.result}`);
const myGasPrice = units.toQa('2000', units.Units.Li); // Gas Price that will be used by all transactions
console.log(`My Gas Price ${myGasPrice.toString()}`);
const isGasSufficient = myGasPrice.gte(new BN(minGasPrice.result)); // Checks if your gas price is less than the minimum gas price
console.log(`Is the gas price sufficient? ${isGasSufficient}`);
// Send a transaction to the network
console.log('Sending a payment transaction to the network...');
const tx = await zilliqa.blockchain.createTransaction(
// Notice here we have a default function parameter named toDs which means the priority of the transaction.
// If the value of toDs is false, then the transaction will be sent to a normal shard, otherwise, the transaction.
// will be sent to ds shard. More info on design of sharding for smart contract can be found in.
// https://blog.zilliqa.com/provisioning-sharding-for-smart-contracts-a-design-for-zilliqa-cd8d012ee735.
// For payment transaction, it should always be false.
zilliqa.transactions.new(
{
version: VERSION,
toAddr: '0xA54E49719267E8312510D7b78598ceF16ff127CE',
amount: new BN(units.toQa('1', units.Units.Zil)), // Sending an amount in Zil (1) and converting the amount to Qa
gasPrice: myGasPrice, // Minimum gasPrice veries. Check the `GetMinimumGasPrice` on the blockchain
gasLimit: Long.fromNumber(50),
},
false,
),
);
console.log(`The transaction status is:`);
console.log(tx.receipt);
// Deploy a contract
console.log(`Deploying a new contract....`);
const code = `scilla_version 0
(* HelloWorld contract *)
import ListUtils
(***************************************************)
(* Associated library *)
(***************************************************)
library HelloWorld
let not_owner_code = Int32 1
let set_hello_code = Int32 2
(***************************************************)
(* The contract definition *)
(***************************************************)
contract HelloWorld
(owner: ByStr20)
field welcome_msg : String = ""
transition setHello (msg : String)
is_owner = builtin eq owner _sender;
match is_owner with
| False =>
e = {_eventname : "setHello()"; code : not_owner_code};
event e
| True =>
welcome_msg := msg;
e = {_eventname : "setHello()"; code : set_hello_code};
event e
end
end
transition getHello ()
r <- welcome_msg;
e = {_eventname: "getHello()"; msg: r};
event e
end`;
const init = [
// this parameter is mandatory for all init arrays
{
vname: '_scilla_version',
type: 'Uint32',
value: '0',
},
{
vname: 'owner',
type: 'ByStr20',
value: `${address}`,
},
];
// Instance of class Contract
const contract = zilliqa.contracts.new(code, init);
// Deploy the contract.
// Also notice here we have a default function parameter named toDs as mentioned above.
// A contract can be deployed at either the shard or at the DS. Always set this value to false.
const [deployTx, hello] = await contract.deploy(
{
version: VERSION,
gasPrice: myGasPrice,
gasLimit: Long.fromNumber(10000),
},
33,
1000,
false,
);
// Introspect the state of the underlying transaction
console.log(`Deployment Transaction ID: ${deployTx.id}`);
console.log(`Deployment Transaction Receipt:`);
console.log(deployTx.txParams.receipt);
// Get the deployed contract address
console.log('The contract address is:');
console.log(hello.address);
//Following line added to fix issue https://github.com/Zilliqa/zilliqa-js/issues/168
const deployedContract = zilliqa.contracts.at(hello.address);
// Create a new timebased message and call setHello
// Also notice here we have a default function parameter named toDs as mentioned above.
// For calling a smart contract, any transaction can be processed in the DS but not every transaction can be processed in the shards.
// For those transactions are involved in chain call, the value of toDs should always be true.
// If a transaction of contract invocation is sent to a shard and if the shard is not allowed to process it, then the transaction will be dropped.
const newMsg = 'Hello, the time is ' + Date.now();
console.log('Calling setHello transition with msg: ' + newMsg);
const callTx = await hello.call(
'setHello',
[
{
vname: 'msg',
type: 'String',
value: newMsg,
},
],
{
// amount, gasPrice and gasLimit must be explicitly provided
version: VERSION,
amount: new BN(0),
gasPrice: myGasPrice,
gasLimit: Long.fromNumber(8000),
},
33,
1000,
false,
);
// Retrieving the transaction receipt (See note 2)
console.log(JSON.stringify(callTx.receipt, null, 4));
//Get the contract state
console.log('Getting contract state...');
const state = await deployedContract.getState();
console.log('The state of the contract is:');
console.log(JSON.stringify(state, null, 4));
} catch (err) {
console.log(err);
}
}
testBlockchain();
The account balance is an object with two fields, balance
and nonce
.
balance
is the account balance in Qa, which is the lowest denomination in Zilliqa. For more information about gas accounting, please refer to here: https://forum.zilliqa.com/t/gas-accounting-in-zilliqa/199
nonce
is a counter that keeps track of how many transactions are sent from a given address. In Zilliqa, every transaction sent from an address must have a unique nonce.
{ "balance": "296505000000000", "nonce": "3" }
An example of a transaction receipt is this:
{
"cumulative_gas": 357,
"epoch_num": "676201",
"event_logs": [
{
"_eventname": "setHello()",
"address": "0x7a4aa130650396ab7c4006c471576a8404f5092b",
"params": [
{
"type": "Int32",
"value": "2",
"vname": "code"
}
]
}
],
"success": true
}
event_logs
comprises of all the events emitted in the transaction. For example, if your transaction calls a transition which emits 3 events, it will be an array of three events. The address
is the contract address of the contract which emits the event.
success
indicates if the transaction is successful.
For more examples, visit this repository.
Each package contains API documentation. For convenience, these are links to the respective README
documents.
Also, you can use viewblock library to interface with ViewBlock's APIs.
This repository makes use of several technologies to provide a better and faster development experience for contributors, and has to be bootstrapped before one can do productive work.
zilliqa-js
leverages Project References, which is available in TypeScript from version 3.x
. As such, the build process is slightly different.
# install all dependencies and shared devDependencies
yarn install
# symlink packages, compile TS source files, and generate protobuf files.
yarn bootstrap
# watch TS source files and recompile on change
yarn build:ts -w
Tests for each package reside in packages/src/*/tests
, and are run using jest
.
We can easily simulate a publish using Verdaccio which is a private npm proxy registry. For more details check tasks/local-registry.sh
zilliqa-js
is bundled using rollup
. To build the distributable bundles, simple run yarn bundle
. This will output two bundles, *.umd.js
and *.esm.js
, to packages/*/dist
. Node.js clients are pointed to the umd
bundle, and bundlers are pointed to esm
.
NOTE: these bundles are not minified.
To build an all-in-one static js file, first install webpack
globally using yarn global add webpack
. Then run yarn build:web
. This will generate a dist
folder in the current path, which contains a file called zilliqa.min.js
. It can be used in normal html file. (A more specific example please refer to example/webpack
)
NOTE: there may be some issue to install webpack with npm, thus using yarn is a recommended way
Download Details:
Author: Zilliqa
Source Code: https://github.com/Zilliqa/zilliqa-js
License: GPL-3.0 license
#Zilliqa #blockchain #smartcontract #typescript #javascript
1632537859
Not babashka. Node.js babashka!?
Ad-hoc CLJS scripting on Node.js.
Experimental. Please report issues here.
Nbb's main goal is to make it easy to get started with ad hoc CLJS scripting on Node.js.
Additional goals and features are:
Nbb requires Node.js v12 or newer.
CLJS code is evaluated through SCI, the same interpreter that powers babashka. Because SCI works with advanced compilation, the bundle size, especially when combined with other dependencies, is smaller than what you get with self-hosted CLJS. That makes startup faster. The trade-off is that execution is less performant and that only a subset of CLJS is available (e.g. no deftype, yet).
Install nbb
from NPM:
$ npm install nbb -g
Omit -g
for a local install.
Try out an expression:
$ nbb -e '(+ 1 2 3)'
6
And then install some other NPM libraries to use in the script. E.g.:
$ npm install csv-parse shelljs zx
Create a script which uses the NPM libraries:
(ns script
(:require ["csv-parse/lib/sync$default" :as csv-parse]
["fs" :as fs]
["path" :as path]
["shelljs$default" :as sh]
["term-size$default" :as term-size]
["zx$default" :as zx]
["zx$fs" :as zxfs]
[nbb.core :refer [*file*]]))
(prn (path/resolve "."))
(prn (term-size))
(println (count (str (fs/readFileSync *file*))))
(prn (sh/ls "."))
(prn (csv-parse "foo,bar"))
(prn (zxfs/existsSync *file*))
(zx/$ #js ["ls"])
Call the script:
$ nbb script.cljs
"/private/tmp/test-script"
#js {:columns 216, :rows 47}
510
#js ["node_modules" "package-lock.json" "package.json" "script.cljs"]
#js [#js ["foo" "bar"]]
true
$ ls
node_modules
package-lock.json
package.json
script.cljs
Nbb has first class support for macros: you can define them right inside your .cljs
file, like you are used to from JVM Clojure. Consider the plet
macro to make working with promises more palatable:
(defmacro plet
[bindings & body]
(let [binding-pairs (reverse (partition 2 bindings))
body (cons 'do body)]
(reduce (fn [body [sym expr]]
(let [expr (list '.resolve 'js/Promise expr)]
(list '.then expr (list 'clojure.core/fn (vector sym)
body))))
body
binding-pairs)))
Using this macro we can look async code more like sync code. Consider this puppeteer example:
(-> (.launch puppeteer)
(.then (fn [browser]
(-> (.newPage browser)
(.then (fn [page]
(-> (.goto page "https://clojure.org")
(.then #(.screenshot page #js{:path "screenshot.png"}))
(.catch #(js/console.log %))
(.then #(.close browser)))))))))
Using plet
this becomes:
(plet [browser (.launch puppeteer)
page (.newPage browser)
_ (.goto page "https://clojure.org")
_ (-> (.screenshot page #js{:path "screenshot.png"})
(.catch #(js/console.log %)))]
(.close browser))
See the puppeteer example for the full code.
Since v0.0.36, nbb includes promesa which is a library to deal with promises. The above plet
macro is similar to promesa.core/let
.
$ time nbb -e '(+ 1 2 3)'
6
nbb -e '(+ 1 2 3)' 0.17s user 0.02s system 109% cpu 0.168 total
The baseline startup time for a script is about 170ms seconds on my laptop. When invoked via npx
this adds another 300ms or so, so for faster startup, either use a globally installed nbb
or use $(npm bin)/nbb script.cljs
to bypass npx
.
Nbb does not depend on any NPM dependencies. All NPM libraries loaded by a script are resolved relative to that script. When using the Reagent module, React is resolved in the same way as any other NPM library.
To load .cljs
files from local paths or dependencies, you can use the --classpath
argument. The current dir is added to the classpath automatically. So if there is a file foo/bar.cljs
relative to your current dir, then you can load it via (:require [foo.bar :as fb])
. Note that nbb
uses the same naming conventions for namespaces and directories as other Clojure tools: foo-bar
in the namespace name becomes foo_bar
in the directory name.
To load dependencies from the Clojure ecosystem, you can use the Clojure CLI or babashka to download them and produce a classpath:
$ classpath="$(clojure -A:nbb -Spath -Sdeps '{:aliases {:nbb {:replace-deps {com.github.seancorfield/honeysql {:git/tag "v2.0.0-rc5" :git/sha "01c3a55"}}}}}')"
and then feed it to the --classpath
argument:
$ nbb --classpath "$classpath" -e "(require '[honey.sql :as sql]) (sql/format {:select :foo :from :bar :where [:= :baz 2]})"
["SELECT foo FROM bar WHERE baz = ?" 2]
Currently nbb
only reads from directories, not jar files, so you are encouraged to use git libs. Support for .jar
files will be added later.
The name of the file that is currently being executed is available via nbb.core/*file*
or on the metadata of vars:
(ns foo
(:require [nbb.core :refer [*file*]]))
(prn *file*) ;; "/private/tmp/foo.cljs"
(defn f [])
(prn (:file (meta #'f))) ;; "/private/tmp/foo.cljs"
Nbb includes reagent.core
which will be lazily loaded when required. You can use this together with ink to create a TUI application:
$ npm install ink
ink-demo.cljs
:
(ns ink-demo
(:require ["ink" :refer [render Text]]
[reagent.core :as r]))
(defonce state (r/atom 0))
(doseq [n (range 1 11)]
(js/setTimeout #(swap! state inc) (* n 500)))
(defn hello []
[:> Text {:color "green"} "Hello, world! " @state])
(render (r/as-element [hello]))
Working with callbacks and promises can become tedious. Since nbb v0.0.36 the promesa.core
namespace is included with the let
and do!
macros. An example:
(ns prom
(:require [promesa.core :as p]))
(defn sleep [ms]
(js/Promise.
(fn [resolve _]
(js/setTimeout resolve ms))))
(defn do-stuff
[]
(p/do!
(println "Doing stuff which takes a while")
(sleep 1000)
1))
(p/let [a (do-stuff)
b (inc a)
c (do-stuff)
d (+ b c)]
(prn d))
$ nbb prom.cljs
Doing stuff which takes a while
Doing stuff which takes a while
3
Also see API docs.
Since nbb v0.0.75 applied-science/js-interop is available:
(ns example
(:require [applied-science.js-interop :as j]))
(def o (j/lit {:a 1 :b 2 :c {:d 1}}))
(prn (j/select-keys o [:a :b])) ;; #js {:a 1, :b 2}
(prn (j/get-in o [:c :d])) ;; 1
Most of this library is supported in nbb, except the following:
:syms
.-x
notation. In nbb, you must use keywords.See the example of what is currently supported.
See the examples directory for small examples.
Also check out these projects built with nbb:
See API documentation.
See this gist on how to convert an nbb script or project to shadow-cljs.
Prequisites:
To build:
bb release
Run bb tasks
for more project-related tasks.
Download Details:
Author: borkdude
Download Link: Download The Source Code
Official Website: https://github.com/borkdude/nbb
License: EPL-1.0
#node #javascript
1655494920
Allows you to interact with the Zilliqa network nodes.
zilliqa-js
is structured as a Lerna monorepo. Each package roughly corresponds to a discrete ZilliqaModule
, most of which can be used independently.
The only required package is @zilliqa-js/core
, which contains the default HTTPProvider
, and other core abstractions that are necessary for other modules to function.
The following table provides a description of each module and what you may want to use it for.
Package | Version | Description | Dependencies |
---|---|---|---|
@zilliqa-js/core | Core abstractions and base classes, such as HTTPProvider and network logic for interfacing with the Zilliqa JSON-RPC. | ||
@zilliqa-js/util | Miscellaneous functions that take care of serialisation/deserialisation and validation. | ||
@zilliqa-js/crypto | Exposes several loosely-coupled cryptographic convenience functions for working with the Zilliqa blockchain and its cryptographic primitives, such as Schnorr signatures. | @zilliqa-js/util | |
@zilliqa-js/proto | Protobuf source files and corresponding generated JS modules. | ||
@zilliqa-js/account | Wallet , Account and Transaction abstractions. | @zilliqa-js/core , @zilliqa-js/crypto , @zilliqa-js/proto | |
@zilliqa-js/blockchain | Main interface to the Zilliqa JSON-RPC . | @zilliqa-js/account | |
@zilliqa-js/contract | Exposes a Contracts module that takes care of smart contract deployment and interaction. | @zilliqa-js/blockchain | |
@zilliqa-js/subscriptions | Classes to interact with the websocket API of Zilliqa node. | ||
@zilliqa-js/scilla-json-utils | Simplifies the way you construct the Scilla JSON data. | ||
@zilliqa-js/viewblock | Library interfacing with ViewBlock's APIs. This package is maintained by Ashlar | @zilliqa-js/crypto |
zilliqa-js
uses scrypt
library which depends on node-gyp
in order to compile the binaries from source on Windows. node-gyp
on Windows requires users to install additional Visual Studio Build tools.
To install the required Visual Studio Build tools:
npm install --global --production windows-build-tools # from an elevated PowerShell or CMD.exe as Administrator
npm config set msvs_version 2015 # 2015 is more compatible; though 2017 may work too
Refer to https://github.com/nodejs/node-gyp#installation for more information about node-gyp
installation on Windows.
It is recommended that developers install the JavaScript client by making use of the umbrella package @zilliqa-js/zilliqa
. This takes care of bootstrapping the various modules, which are then accessible as members of the Zilliqa
class.
npm i @zilliqa-js/zilliqa
# or
yarn add @zilliqa-js/zilliqa
You can create a test account by using Zilliqa Dev Wallet and request funds by using ZIL Faucet service.
const { BN, Long, bytes, units } = require('@zilliqa-js/util');
const { Zilliqa } = require('@zilliqa-js/zilliqa');
const {
toBech32Address,
getAddressFromPrivateKey,
} = require('@zilliqa-js/crypto');
const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
// These are set by the core protocol, and may vary per-chain.
// You can manually pack the bytes according to chain id and msg version.
// For more information: https://apidocs.zilliqa.com/?shell#getnetworkid
const chainId = 333; // chainId of the developer testnet
const msgVersion = 1; // current msgVersion
const VERSION = bytes.pack(chainId, msgVersion);
// Populate the wallet with an account
const privateKey =
'3375F915F3F9AE35E6B301B7670F53AD1A5BE15D8221EC7FD5E503F21D3450C8';
zilliqa.wallet.addByPrivateKey(privateKey);
const address = getAddressFromPrivateKey(privateKey);
console.log(`My account address is: ${address}`);
console.log(`My account bech32 address is: ${toBech32Address(address)}`);
async function testBlockchain() {
try {
// Get Balance
const balance = await zilliqa.blockchain.getBalance(address);
// Get Minimum Gas Price from blockchain
const minGasPrice = await zilliqa.blockchain.getMinimumGasPrice();
// Account balance (See note 1)
console.log(`Your account balance is:`);
console.log(balance.result);
console.log(`Current Minimum Gas Price: ${minGasPrice.result}`);
const myGasPrice = units.toQa('2000', units.Units.Li); // Gas Price that will be used by all transactions
console.log(`My Gas Price ${myGasPrice.toString()}`);
const isGasSufficient = myGasPrice.gte(new BN(minGasPrice.result)); // Checks if your gas price is less than the minimum gas price
console.log(`Is the gas price sufficient? ${isGasSufficient}`);
// Send a transaction to the network
console.log('Sending a payment transaction to the network...');
const tx = await zilliqa.blockchain.createTransaction(
// Notice here we have a default function parameter named toDs which means the priority of the transaction.
// If the value of toDs is false, then the transaction will be sent to a normal shard, otherwise, the transaction.
// will be sent to ds shard. More info on design of sharding for smart contract can be found in.
// https://blog.zilliqa.com/provisioning-sharding-for-smart-contracts-a-design-for-zilliqa-cd8d012ee735.
// For payment transaction, it should always be false.
zilliqa.transactions.new(
{
version: VERSION,
toAddr: '0xA54E49719267E8312510D7b78598ceF16ff127CE',
amount: new BN(units.toQa('1', units.Units.Zil)), // Sending an amount in Zil (1) and converting the amount to Qa
gasPrice: myGasPrice, // Minimum gasPrice veries. Check the `GetMinimumGasPrice` on the blockchain
gasLimit: Long.fromNumber(50),
},
false,
),
);
console.log(`The transaction status is:`);
console.log(tx.receipt);
// Deploy a contract
console.log(`Deploying a new contract....`);
const code = `scilla_version 0
(* HelloWorld contract *)
import ListUtils
(***************************************************)
(* Associated library *)
(***************************************************)
library HelloWorld
let not_owner_code = Int32 1
let set_hello_code = Int32 2
(***************************************************)
(* The contract definition *)
(***************************************************)
contract HelloWorld
(owner: ByStr20)
field welcome_msg : String = ""
transition setHello (msg : String)
is_owner = builtin eq owner _sender;
match is_owner with
| False =>
e = {_eventname : "setHello()"; code : not_owner_code};
event e
| True =>
welcome_msg := msg;
e = {_eventname : "setHello()"; code : set_hello_code};
event e
end
end
transition getHello ()
r <- welcome_msg;
e = {_eventname: "getHello()"; msg: r};
event e
end`;
const init = [
// this parameter is mandatory for all init arrays
{
vname: '_scilla_version',
type: 'Uint32',
value: '0',
},
{
vname: 'owner',
type: 'ByStr20',
value: `${address}`,
},
];
// Instance of class Contract
const contract = zilliqa.contracts.new(code, init);
// Deploy the contract.
// Also notice here we have a default function parameter named toDs as mentioned above.
// A contract can be deployed at either the shard or at the DS. Always set this value to false.
const [deployTx, hello] = await contract.deploy(
{
version: VERSION,
gasPrice: myGasPrice,
gasLimit: Long.fromNumber(10000),
},
33,
1000,
false,
);
// Introspect the state of the underlying transaction
console.log(`Deployment Transaction ID: ${deployTx.id}`);
console.log(`Deployment Transaction Receipt:`);
console.log(deployTx.txParams.receipt);
// Get the deployed contract address
console.log('The contract address is:');
console.log(hello.address);
//Following line added to fix issue https://github.com/Zilliqa/zilliqa-js/issues/168
const deployedContract = zilliqa.contracts.at(hello.address);
// Create a new timebased message and call setHello
// Also notice here we have a default function parameter named toDs as mentioned above.
// For calling a smart contract, any transaction can be processed in the DS but not every transaction can be processed in the shards.
// For those transactions are involved in chain call, the value of toDs should always be true.
// If a transaction of contract invocation is sent to a shard and if the shard is not allowed to process it, then the transaction will be dropped.
const newMsg = 'Hello, the time is ' + Date.now();
console.log('Calling setHello transition with msg: ' + newMsg);
const callTx = await hello.call(
'setHello',
[
{
vname: 'msg',
type: 'String',
value: newMsg,
},
],
{
// amount, gasPrice and gasLimit must be explicitly provided
version: VERSION,
amount: new BN(0),
gasPrice: myGasPrice,
gasLimit: Long.fromNumber(8000),
},
33,
1000,
false,
);
// Retrieving the transaction receipt (See note 2)
console.log(JSON.stringify(callTx.receipt, null, 4));
//Get the contract state
console.log('Getting contract state...');
const state = await deployedContract.getState();
console.log('The state of the contract is:');
console.log(JSON.stringify(state, null, 4));
} catch (err) {
console.log(err);
}
}
testBlockchain();
The account balance is an object with two fields, balance
and nonce
.
balance
is the account balance in Qa, which is the lowest denomination in Zilliqa. For more information about gas accounting, please refer to here: https://forum.zilliqa.com/t/gas-accounting-in-zilliqa/199
nonce
is a counter that keeps track of how many transactions are sent from a given address. In Zilliqa, every transaction sent from an address must have a unique nonce.
{ "balance": "296505000000000", "nonce": "3" }
An example of a transaction receipt is this:
{
"cumulative_gas": 357,
"epoch_num": "676201",
"event_logs": [
{
"_eventname": "setHello()",
"address": "0x7a4aa130650396ab7c4006c471576a8404f5092b",
"params": [
{
"type": "Int32",
"value": "2",
"vname": "code"
}
]
}
],
"success": true
}
event_logs
comprises of all the events emitted in the transaction. For example, if your transaction calls a transition which emits 3 events, it will be an array of three events. The address
is the contract address of the contract which emits the event.
success
indicates if the transaction is successful.
For more examples, visit this repository.
Each package contains API documentation. For convenience, these are links to the respective README
documents.
Also, you can use viewblock library to interface with ViewBlock's APIs.
This repository makes use of several technologies to provide a better and faster development experience for contributors, and has to be bootstrapped before one can do productive work.
zilliqa-js
leverages Project References, which is available in TypeScript from version 3.x
. As such, the build process is slightly different.
# install all dependencies and shared devDependencies
yarn install
# symlink packages, compile TS source files, and generate protobuf files.
yarn bootstrap
# watch TS source files and recompile on change
yarn build:ts -w
Tests for each package reside in packages/src/*/tests
, and are run using jest
.
We can easily simulate a publish using Verdaccio which is a private npm proxy registry. For more details check tasks/local-registry.sh
zilliqa-js
is bundled using rollup
. To build the distributable bundles, simple run yarn bundle
. This will output two bundles, *.umd.js
and *.esm.js
, to packages/*/dist
. Node.js clients are pointed to the umd
bundle, and bundlers are pointed to esm
.
NOTE: these bundles are not minified.
To build an all-in-one static js file, first install webpack
globally using yarn global add webpack
. Then run yarn build:web
. This will generate a dist
folder in the current path, which contains a file called zilliqa.min.js
. It can be used in normal html file. (A more specific example please refer to example/webpack
)
NOTE: there may be some issue to install webpack with npm, thus using yarn is a recommended way
Download Details:
Author: Zilliqa
Source Code: https://github.com/Zilliqa/zilliqa-js
License: GPL-3.0 license
#Zilliqa #blockchain #smartcontract #typescript #javascript
1606217442
In all the market sectors, Blockchain technology has contributed to the redesign. The improvements that were once impossible have been pushed forward. Blockchain is one of the leading innovations with the ability to influence the various sectors of the industry. It also has the ability to be one of the career-influencing innovations at the same time. We have seen an increasing inclination towards the certification of the Blockchain in recent years, and there are obvious reasons behind it. Blockchain has everything to offer, from good packages to its universal application and futuristic development. Let’s address the reasons why one should go for Blockchain certification.
5 advantages of certification by Blockchain:
1. Lucrative packages- Everyone who completes their education or upskills themselves wants to end up with a good bundle, not only is one assured of a good learning experience with Blockchain, but the packages are drool-worthy at the same time. A Blockchain developer’s average salary varies between $150,000 and $175,000 per annum. Comparatively, a software developer gets a $137,000 per year salary. For a Blockchain developer, the San Francisco Bay area provides the highest bundle, amounting to $162,288 per annum. There’s no point arguing that learning about Blockchain is a smart decision with such lucrative packages.
2. Growing industry- When you select any qualification course, it becomes important that you choose a growing segment or industry that promises potential in the future. You should anticipate all of these with Blockchain. The size of the blockchain market is expected to rise from USD 3.0 billion in 2020 to USD 39.7 billion by 2025. This will see an incredible 67.3 percent CAGR between 2020-2025. To help business processes, several businesses are outsourcing Blockchain technologies. This clearly demonstrates that there will be higher demand in the future for Blockchain developers and certified Blockchain professionals.
3. Universal application- One of the major reasons for the success of Blockchain is that it has a global application. It is not sector-specific. Blockchain usage cases are discovered by almost all market segments. In addition, other innovations such as AI, big data, data science and much more are also supported by Blockchain. It becomes easier to get into a suitable industry once you know about Blockchain.
**4. Work protection-**Surely you would like to invest in an ability that ensures job security. You had the same chance for Blockchain. Since this is the technology of the future, understanding that Blockchain can keep up with futuristic developments will help in a successful and safe job.
**5.**After a certain point of your professional life, you are expected to learn about new abilities that can help enhance your skills. Upskilling is paramount. Upskilling oneself has become the need for the hour, and choosing a path that holds a lot of potential for the future is the best way to do this. For all computer geeks and others who want to gain awareness of emerging technology, Blockchain is a good option.
Concluding thoughts- opting for Blockchain certification is a successful career move with all these advantages. You will be able to find yourself in a safe and secured work profile once you have all the knowledge and information. Link for Blockchain certification programme with the Blockchain Council.
#blockchain certificate #blockchain training #blockchain certification #blockchain developers #blockchain #blockchain council
1592668860
In this tutorial, we’ll read about the Android SDK Manager. We will see what is SDK manager in Android and why and how it is important for Android. So, SDK stands for Software Development Kit, which is a collection of software tools required. SDK basically helps Android to download tools and recent versions of Android. Every time a new Android version is released, along with it is released an SDK corresponding to it. This SDK must be installed by the developers for the devices.
What is SDK Manager?
A Software development kit is a set of tools required for the development of applications for Android. It also ensures that the progress of App development goes as flat as pancakes. We need SDK irrespective of the language we are using. Android SDK comes wrapped up with the Android Studio these days. An Android SDK separates the tools, platforms and other components into packages. These can be downloaded from the SDK Manager.
#android tutorials #android sdk manager #android sdk manager download #android sdk tools #android studio sdk manager #sdk download #sdk manager #sdk tools
1561445270
We, at HireFullStackDeveloperIndia, implement the right strategic approach to offer a wide variety through customized Vue.js development services to suit your requirements at most competitive prices.
Vue.js is an open-source JavaScript framework that is incredibly progressive and adoptive and majorly used to build a breathtaking user interface. Vue.js is efficient to create advanced web page applications.
Vue.js gets its strength from the flexible JavaScript library to build an enthralling user interface. As the core of Vue.js is concentrated which provides a variety of interactive components for the web and gives real-time implementation. It gives freedom to developers by giving fluidity and eases the integration process with existing projects and other libraries that enables to structure of a highly customizable application.
Vue.js is a scalable framework with a robust in-build stack that can extend itself to operate apps of any proportion. Moreover, vue.js is the best framework to seamlessly create astonishing single-page applications.
Our Vue.js developers have gained tremendous expertise by delivering services to clients worldwide over multiple industries in the area of front-end development. Our adept developers are experts in Vue development and can provide the best value-added user interfaces and web apps.
We assure our clients to have a prime user interface that reaches end-users and target the audience with the exceptional user experience across a variety of devices and platforms. Our expert team of developers serves your business to move ahead on the path of success, where your enterprise can have an advantage over others.
Here are some key benefits that you can avail when you decide to hire vue.js developers in USA from HireFullStackDeveloperIndia:
If you are looking to hire React Native developers in USA, then choosing HireFullStackDeveloperIndia would be the best as we offer some of the best talents when it comes to Vue.js.
#javascript #vue-js #web-development #node-js #reactjs #mobile-apps #angular-js #blockchain #ios #react-native #laravel #jquery #web-service #html5 #go #sql-server #user-experience #facebook #ember-js #symfony #raspberry-pi