Yii2 asset bundle for library web3.js v0.20.2
This package provide AssetBundle for web3js library, (*1)
To install Yii2 Web3js Asset run:, (*2)
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:, (*3)
console.log(web3); // {eth: .., shh: ...} // it's here!
Set a provider (HttpProvider), (*4)
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), (*5)
web3.setProvider(new web3.providers.HttpProvider('http://host.url', 0, BasicAuthUsername, BasicAuthPassword));
There you go, now you can use it:, (*6)
var coinbase = web3.eth.coinbase;
var balance = web3.eth.getBalance(coinbase);
You can find more examples in example
directory., (*7)
Caution!
Web3.js library in development, a lot of bugs and unpredictable behaviors expects you =), (*8)