
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
ethereum-web3-plus
Advanced tools
Adds some simplifications to the web3 package such as compilation, instance creation, call sequencing
Package that sits on top of web3 package by frozeman. This package adds 2 main functionalities:
You need to run a local Ethereum node to use this library.
npm install ethereum-web3-plus --save
meteor npm install ethereum-web3-plus --save
Loading the packages. Second require will modify Web3 prototype
var Web3 = require('web3');
require('ethereum-web3-plus'); // modify Web3 prototype
Initializing Web3 API normally. Also see web3 package documentation
let ethereum_url = "http://localhost:8545";
web3 = new Web3(new Web3.providers.HttpProvider(ethereum_url));
console.log("Connected to Geth console", web3.version.node, "on block", eth.blockNumber);
eth.defaultAccount = eth.coinbase;
web3.personal.unlockAccount(eth.defaultAccount, "capture your password here", 10);
output: Connected to Geth console Geth/v1.5.8-stable-f58fb322/darwin/go1.7.5 on block 62353
Using the solidity compiler functionality: Note the path resolution is relative to the path where the geth node is running.
var compiler = web3.solidityCompiler();
compiler.addDeployedLib("MapString", "0x48f59e9fbce7880a11acd90dc2f99b28accc47f6");
compiler.addDeployedLib("MapAddress", "0xdb3d0da48c1962f5e31abd9f9904160729da9358");
compiler.addDeployedLib("MapAddressWithProps", "0x87614301dd92d49447b926941940c85533b7e147");
compiler.compile("./sources/example.sol"); // path either absolute or relative to geth running node.
compiler.displaySizes(); // display all contract found and compiled and their code size (important to check they are as small as possible)
compiler.displayMissingLibs(); // display libraries that have not been found in the deployed libs and that are required.
output: Compiled Example code length: 1440
Using the contract deployment functions
// request the publication of the contract. Returns the tx hash of that request
var tx = web3.newInstanceTx("Example", any constructor params);
// convert a contract address into an javascript object
var address = "0x4435dee6dd53ffad11cf4ebb85cea2e51ea62434";
var E = web3.instanceAt("Example", address);
Using the block watcher functionalities
bw= web3.BlockWatcherStart(func*);
It is possible to pass a function in parameter to the BlockWatcherStart function to wrap the callbacks. This function parameter is optional and if not supplied, a simplest version is used (simpleWrapper). This is necessary for some environment like Meteor where the callback must run in the proper context (eg Fiber). So the function must work as follow: accept a callback as unique parameter. When called returns a function that wrap the callback
simpleWrapper = function(f) {
return function() { return f.apply(f, arguments); }
}
// for instance in Meteor
web3.BlockWatcherStart(Meteor.bindEnvironment);
Deploying a contract
web3.waitFor( web3.newInstanceTx("Example"), "Param1",
function(tx, p1, contract, err) {
console.log("callback:", tx, p1, contract, err);
if(contract) E = web3.instanceAt("Example", contract);
},
{canonicalAfter:2, dropAfter:5} );
// when you want to stop watching the blocks
bw.stop();
waitFor takes the following parameters:
- 1 : a valid tx hash returned by any of the web3 calls
- 2..N: any parameters to be passed to the callback
- N+1 : a callback in the form function(txHash, p2, ..., pN, contractAddress, error)
where txHash is the hash of the transaction that was waited to be executed
p2, ..., pN the custom paramters passed to the waitFor
contractAddress is the newly created contract in case the transaction is deploying a contract
or the address of the contract (or account) to which the transaction was made
- N+2 : (optional) an object with the following attributes
- canonicalAfter: <number>, default=0. tells the watcher to call the callback only canonicalAfter blocks after the transaction has been mined. This allow to control possible small soft forks and be sure to get valid transactions.
- dropAfter: <number>, default=99999999. tells the watcher to drop this transaction if not mined after dropAfter blocks. This in case the local node has been killed before sending the tx to other nodes and/or the watcher loosing the events listener.
FAQs
Adds some simplifications to the web3 package such as compilation, instance creation, call sequencing, events readers
The npm package ethereum-web3-plus receives a total of 1 weekly downloads. As such, ethereum-web3-plus popularity was classified as not popular.
We found that ethereum-web3-plus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.