file-force

Форк
0
/
libethereum.js 
74 строки · 1.7 Кб
1
/*
2
 *   Copyright (C) 2017 Igor Konovalov
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *   http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16

17
const Web3 = require('web3');
18

19
class Ethereum {
20

21
    constructor(config) {
22
        this._web3 = new Web3();
23
        this.web3.setProvider(new this.web3.providers.HttpProvider(config.eth.api));
24
        this._eth = this.web3.eth;
25
    }
26

27
    get web3() {
28
        return this._web3;
29
    }
30

31
    get eth() {
32
        return this._eth;
33
    }
34

35
    get lastBlock() {
36
        return this.eth.getBlock('latest')
37
    }
38

39
    listAccounts() {
40
        return this.eth.accounts;
41
    }
42

43
    coinbase() {
44
        return this.eth.coinbase
45
    }
46

47
    getBalance(account, units = 'ether') {
48
        return this.web3.fromWei(this.eth.getBalance(account), units)
49
    }
50

51
    txCount(address) {
52
        return this.eth.getTransactionCount(address);
53
    }
54

55
    txCountWithPending(address) {
56
        return this.eth.getTransactionCount(address, 'pending')
57
    }
58

59
    get gasPrice() {
60
        return this.eth.gasPrice;
61
    }
62

63
    get defaultAccount() {
64
        return this.eth.defaultAccount;
65
    }
66

67
    sendRawTransaction(tx) {
68
        let txHash = this.eth.sendRawTransaction(tx);
69
        return txHash;
70
    }
71

72
}
73

74
module.exports = Ethereum;

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.