-
Notifications
You must be signed in to change notification settings - Fork 494
/
index.js
63 lines (49 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* global global require */
const Web3 = require('web3');
const __embarkWeb3 = {};
__embarkWeb3.init = function(config) {
global.web3 = config.web3 || global.web3;
// Check if the global web3 object uses the old web3 (0.x)
if (global.web3 && typeof global.web3.version !== 'string') {
// If so, use a new instance using 1.0, but use its provider
this.web3 = new Web3(global.web3.currentProvider);
} else {
this.web3 = global.web3 || new Web3();
}
global.web3 = this.web3;
};
__embarkWeb3.getInstance = function () {
return this.web3;
};
__embarkWeb3.getAccounts = function () {
return this.web3.eth.getAccounts(...arguments);
};
__embarkWeb3.getNewProvider = function (providerName, ...args) {
return new Web3.providers[providerName](...args);
};
__embarkWeb3.setProvider = function (provider) {
return this.web3.setProvider(provider);
};
__embarkWeb3.getCurrentProvider = function () {
return this.web3.currentProvider;
};
__embarkWeb3.getDefaultAccount = function () {
return this.web3.eth.defaultAccount;
};
__embarkWeb3.setDefaultAccount = function (account) {
this.web3.eth.defaultAccount = account;
};
__embarkWeb3.newContract = function (options) {
return new this.web3.eth.Contract(options.abi, options.address);
};
__embarkWeb3.send = function () {
console.log('ARGUEMTNS', ...arguments);
return this.web3.eth.sendTransaction(...arguments);
};
__embarkWeb3.toWei = function () {
return this.web3.utils.toWei(...arguments);
};
__embarkWeb3.getNetworkId = function () {
return this.web3.eth.net.getId();
};
export default __embarkWeb3;