biozahard/yii2-web3js-asset

为 Yii 2.0 框架提供的 Web3.js 库资产包

0.20.2 2017-12-30 20:25 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:41:54 UTC


README

本包提供 web3js 库的 AssetBundle

要安装 Yii2 Web3js Asset,请运行

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

要在您的页面上添加 web3.js,只需添加以下行

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

web3.js 的使用方法

直接从全局命名空间使用 web3 对象

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

设置提供者(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("https://:8545"));
}

设置提供者(使用 HTTP Basic Authentication 的 HttpProvider)

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

现在您可以使用它了

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

您可以在 example 目录中找到更多示例。

注意!

Web3.js 库处于开发阶段,存在许多错误和不可预测的行为,请期待 =)