Esempio n. 1
0
    def eth_estimateGas(self,
                        to_address=None,
                        from_address=None,
                        gas=None,
                        gas_price=None,
                        value=None,
                        data=None,
                        default_block=BLOCK_TAG_LATEST):
        """
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_estimategas

        NEEDS TESTING
        """
        if isinstance(default_block, basestring):
            if default_block not in BLOCK_TAGS:
                raise ValueError
        obj = {}
        if to_address is not None:
            obj['to'] = to_address
        if from_address is not None:
            obj['from'] = from_address
        if gas is not None:
            obj['gas'] = hex(gas)
        if gas_price is not None:
            obj['gasPrice'] = clean_hex(gas_price)
        if value is not None:
            obj['value'] = value
        if data is not None:
            obj['data'] = data
        return hex_to_dec(self.call('eth_estimateGas', [obj, default_block]))
Esempio n. 2
0
    def eth_getBalance(self, address=None, block=BLOCK_TAG_LATEST):
        """ Returns the balance of the account of given address.

        :param address: 20 Bytes - address to check for balance.
        :type address: str
        :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending"
        :type block: int or str
        :return:  integer of the current balance in wei.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_getBalance("0x956b6B7454884b734B29A8115F045a95179ea00C")
        17410594678300000000

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance
        .. todo::
            TESTED

        """
        address = address or self.eth_coinbase()
        block = validate_block(block)
        v = hex_to_dec(self.call('eth_getBalance', [address, block]))
        return (v if v else 0)
Esempio n. 3
0
    def eth_newPendingTransactionFilter(self):
        """
        https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter

        TESTED
        """
        return hex_to_dec(self.call('eth_newPendingTransactionFilter'))
Esempio n. 4
0
    def net_peerCount(self):
        """ Returns number of peers currently connected to the client.

        :return: integer of the number of connected peers.
        :rtype: int

        :Example:
        >>> explorer = EthereumExplorerRPC()
        >>> explorer.net_peerCount()
        25

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#net_peercount
        .. todo::
            TESTED
        """
        return hex_to_dec(self.call('net_peerCount'))
Esempio n. 5
0
    def eth_blockNumber(self):
        """ Returns the number of most recent block.

        :return: integer of the current block number the client is on.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_blockNumber()
        5100196

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber
        .. todo::
            TESTED
        """
        return hex_to_dec(self.call('eth_blockNumber'))
Esempio n. 6
0
    def eth_gasPrice(self):
        """ Returns the current price per gas in wei.

        :return: integer of the current gas price in wei.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_gasPrice()
        4000000000

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice
        .. todo::
            TESTED
        """
        return hex_to_dec(self.call('eth_gasPrice'))
Esempio n. 7
0
    def eth_hashrate(self):
        """ Returns the number of hashes per second that the node is mining with.

        :return: number of hashes per second.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_hashrate()
        0

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_hashrate
        .. todo::
            TESTED
        """

        return hex_to_dec(self.call('eth_hashrate'))
Esempio n. 8
0
    def eth_getUncleCountByBlockNumber(self, block=BLOCK_TAG_LATEST):
        """ Returns the number of uncles in a block from a block matching the given block number.

        :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending"
        :type block: int or str
        :return: integer of the number of uncles in this block.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_getUncleCountByBlockNumber(5100196)
        0

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblocknumber
        .. todo::
            TESTED
        """
        block = validate_block(block)
        return hex_to_dec(self.call('eth_getUncleCountByBlockNumber', [block]))
Esempio n. 9
0
    def eth_getBlockTransactionCountByHash(self, block_hash):
        """ Returns the number of transactions in a block from a block matching the given block hash.

        :param block_hash:  32 Bytes - hash of a block
        :type block_hash: str
        :return: integer of the number of transactions in this block.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_getBlockTransactionCountByHash('0x98a548cbd0cd385f46c9bf28c16bc36dc6ec27207617e236f527716e617ae91b')
        69

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbyhash
        .. todo::
            TESTED
        """
        return hex_to_dec(
            self.call('eth_getBlockTransactionCountByHash', [block_hash]))
Esempio n. 10
0
    def eth_getTransactionCount(self, address, block=BLOCK_TAG_LATEST):
        """ Returns the number of transactions sent from an address.

        :param address: 20 Bytes - address.
        :type address: str
        :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending"
        :type block: int or str
        :return: integer of the number of transactions send from this address.
        :rtype: int

        :Example:

        >>> explorer = EthereumExplorerRPC()
        >>> explorer.eth_getTransactionCount("0x956b6B7454884b734B29A8115F045a95179ea00C")
        12891

        .. seealso::
            https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactioncount
        .. todo::
            TESTED
        """
        block = validate_block(block)
        return hex_to_dec(
            self.call('eth_getTransactionCount', [address, block]))