0x08 智能合约开发之MetaMask
2018-04-05 本文已影响8人
金牛茶馆
节点分类
- light client --- 轻节点
- full client --- 全节点
推荐使用:
MetaMask(小狐狸) https://metamask.io/
- 可以选择不同的网络
- 转账功能
- 交易功能
注意输入的密码为你所设定的密码
初始化web3,选择加载注入插件或者本地testrpc服务
src/utils/getWeb3.js
import Web3 from 'web3'
let getWeb3 = new Promise(function(resolve, reject) {
// Wait for loading completion to avoid race conditions with web3 injection timing.
window.addEventListener('load', function() {
var results
var web3 = window.web3
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider.
web3 = new Web3(web3.currentProvider)
results = {
web3: web3
}
console.log('Injected web3 detected.');
resolve(results)
} else {
// Fallback to localhost if no web3 injection.
var provider = new Web3.providers.HttpProvider('http://localhost:8545')
web3 = new Web3(provider)
results = {
web3: web3
}
console.log('No web3 instance injected, using Local web3.');
resolve(results)
}
})
})
export default getWeb3
添加event 可以增加前端的使用