web3 js

初始化
if (typeof web3 !== ‘undefined’) {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers
.HttpProvider(“http://localhost:8545”));
}

以太单位转换
web3.fromWei web3.toWei
数据类型转换

web3.toString web3.toDecimal web3.toBigNumber
字符编码转换

web3.toHex web3.toAscii web3.toUtf8 web3.fromUtf8
地址相关

web3.isAddress web3.toChecksumAddress

同步:web3.eth.accounts

web3.eth. blockNumber

web3.eth.sendTransaction(transactionObject [, callback])

web3.eth.contract
var MyContract = web3.eth.contract(abiArray);
// 通过地址初始化合约实例
var contractInstance = MyContract.at(address);
// 或者部署一个新合约
var contractInstance = MyContract.new([constructorParam1]
[, constructorParam2], {
data: ‘0x12345…’,
from: myAccount,
gas: 1000000
});

myContractInstance.myMethod.call(param1[, param2, …][,
transactionObject
][, defaultBlock][, callback]);

猜你喜欢

转载自blog.csdn.net/qq_34751210/article/details/127810831