Exemplo n.º 1
0
from ethjsonrpc import EthJsonRpc

c = EthJsonRpc('172.17.0.26', 8545)

print 'Net Version', c.net_version()
print 'web3 client version', c.web3_clientVersion()
print 'gas price', c.eth_gasPrice()
print 'block number', c.eth_blockNumber()
print 'eth syncing', c.eth_syncing()
Exemplo n.º 2
0
#!/usr/bin/env python2.7

from ethjsonrpc import EthJsonRpc
from ethjsonrpc.utils import wei_to_ether, ether_to_wei

c = EthJsonRpc('192.168.1.129', 8545)

from_address = "0x90b983390bef91b17f3a2f2d7eb9121c1214fc6b"
to_address = "0x16Ba1a0e4F6bA1E9B614ae8C25d101eA7441A0a1"

print c.net_version()

print c.web3_clientVersion()

print c.eth_gasPrice()

print c.eth_blockNumber()

print wei_to_ether(c.eth_getBalance(from_address))

print wei_to_ether(c.eth_getBalance(to_address))

# print c.web3_toWei(0.01, "ether")

amount = int(ether_to_wei(0.001))

print type(amount)

print amount

print hex(amount)
Exemplo n.º 3
0
from ethjsonrpc import EthJsonRpc  # to use Parity-specific methods, import ParityEthJsonRpc

base_address = "0xbb1588c5debc2871cd8852c4bd6c6e4cb1d9fe15"
c = EthJsonRpc('127.0.0.1', 8545)
print(c.net_version())
print(c.web3_clientVersion())
print(c.net_listening())
print(c.net_peerCount())
print(c.eth_mining())
print(c.eth_gasPrice())

contract_addr = "0xc1bba31875a1a66eb4794e6e4dd07811fb58b5c5"
my_addr = str(c.eth_coinbase())
print my_addr
tx = c.call_with_transaction(my_addr, contract_addr, 'pushByte(string)',
                             ['Hello, world'])
print(tx)

results = c.call(contract_addr, 'getdata()', [], ['string'])
print(results)
Exemplo n.º 4
0
    def ethereum_sign_tx(self, args):
        from ethjsonrpc import EthJsonRpc
        from ethjsonrpc.utils import hex_to_dec
        import rlp

        value = args.value
        if ' ' in value:
            value, unit = value.split(' ', 1)
            if unit.lower() not in ether_units:
                raise CallException(types.Failure_Other, "Unrecognized ether unit %r" % unit)
            value = int(value) * ether_units[unit.lower()]
        else:
            value = int(value)

        gas_price = args.gas_price
        if gas_price is not None:
            if ' ' in gas_price:
                gas_price, unit = gas_price.split(' ', 1)
                if unit.lower() not in ether_units:
                    raise CallException(types.Failure_Other, "Unrecognized gas price unit %r" % unit)
                gas_price = int(gas_price) * ether_units[unit.lower()]
            else:
                gas_price = int(gas_price)

        gas_limit = args.gas
        if gas_limit is not None:
            gas_limit = int(gas_limit)

        if args.to.startswith('0x') or args.to.startswith('0X'):
            to_address = args.to[2:].decode('hex')
        else:
            to_address = args.to.decode('hex')

        nonce = args.nonce
        if nonce:
            nonce = int(nonce)

        address_n = self.client.expand_path(args.n)
        address = "0x%s" % (binascii.hexlify(self.client.ethereum_get_address(address_n)),)

        if gas_price is None or gas_limit is None or nonce is None:
            host, port = args.host.split(':')
            eth = EthJsonRpc(host, int(port))

        if not args.data:
            args.data = ''
        elif args.data.startswith('0x'):
            args.data = args.data[2:]
        data = binascii.unhexlify(args.data)

        if gas_price is None:
            gas_price = eth.eth_gasPrice()

        if gas_limit is None:
            gas_limit = eth.eth_estimateGas(
                to_address=args.to,
                from_address=address,
                value=("0x%x" % value),
                data="0x"+args.data)

        if nonce is None:
            nonce = eth.eth_getTransactionCount(address)

        sig = self.client.ethereum_sign_tx(
            n=address_n,
            nonce=nonce,
            gas_price=gas_price,
            gas_limit=gas_limit,
            to=to_address,
            value=value,
            data=data,
            chain_id=args.chain_id)

        transaction = rlp.encode(
            (nonce, gas_price, gas_limit, to_address, value, data) + sig)
        tx_hex = '0x%s' % binascii.hexlify(transaction)

        if args.publish:
            tx_hash = eth.eth_sendRawTransaction(tx_hex)
            return 'Transaction published with ID: %s' % tx_hash
        else:
            return 'Signed raw transaction: %s' % tx_hex
Exemplo n.º 5
0
from ethjsonrpc import EthJsonRpc
c = EthJsonRpc('127.0.0.1', 8545)
print(c.eth_gasPrice())
addr_list = c.eth_accounts()
print(addr_list)
print(c.eth_getBalance(addr_list[0], 'latest'))
print(c.eth_getBalance(addr_list[1], 'latest'))
print(c.eth_getTransactionCount (addr_list[0], 'latest'))
#c.eth_sendTransaction(addr_list[0], addr_list[1], 30400, c.eth_gasPrice(), 1000000, 0)
#print(c.db_putString('testDB', 'myKey', 'myString'))
#print(c.db_getString('testDB', 'myKey'))