biozahard/yii2-web3js-asset

Web3.js libgrary asset bundle for Yii 2.0 Framework

Installs: 57

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

0.20.2 2017-12-30 20:25 UTC

This package is not auto-updated.

Last update: 2025-03-02 05:59:55 UTC


README

This package provide AssetBundle for web3js library

To install Yii2 Web3js Asset run:

composer require dmstr/yii2-adminlte-asset "0.20.2"

For adding web3.js on your page just add line:

    biozahard\web3js\Web3jsAssets::register($this);

Usage of web3.js

Use the web3 object directly from global namespace:

console.log(web3); // {eth: .., shh: ...} // it's here!

Set a provider (HttpProvider)

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

Set a provider (HttpProvider using HTTP Basic Authentication)

web3.setProvider(new web3.providers.HttpProvider('http://host.url', 0, BasicAuthUsername, BasicAuthPassword));

There you go, now you can use it:

var coinbase = web3.eth.coinbase;
var balance = web3.eth.getBalance(coinbase);

You can find more examples in example directory.

Caution!

Web3.js library in development, a lot of bugs and unpredictable behaviors expects you =)