Beispiel #1
0
 def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
     if method == 'eth_sendTransaction':
         transaction = params[0]
         if 'gas' not in transaction:
             transaction = assoc(
                 transaction,
                 'gas',
                 hex(get_buffered_gas_estimate(w3, transaction)),
             )
             return make_request(method, [transaction])
     return make_request(method, params)
Beispiel #2
0
    def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]:
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(self.default_account):
            transaction = assoc(transaction, 'from', self.default_account)

        # TODO: move gas estimation in middleware
        if 'gas' not in transaction:
            transaction = assoc(
                transaction,
                'gas',
                get_buffered_gas_estimate(self.web3, transaction),
            )
        return (transaction,)
Beispiel #3
0
    def sendTransaction(self, transaction: TxParams) -> HexBytes:
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(self.defaultAccount):
            transaction = assoc(transaction, 'from', self.defaultAccount)

        # TODO: move gas estimation in middleware
        if 'gas' not in transaction:
            transaction = assoc(
                transaction,
                'gas',
                get_buffered_gas_estimate(self.web3, transaction),
            )

        return self.web3.manager.request_blocking(
            RPC.eth_sendTransaction,
            [transaction],
        )
Beispiel #4
0
    def sendTransaction(self, transaction):
        # TODO: move to middleware
        if 'from' not in transaction and is_checksum_address(self.defaultAccount):
            transaction = assoc(transaction, 'from', self.defaultAccount)

        # TODO: move gas estimation in middleware
        if 'gas' not in transaction:
            transaction = assoc(
                transaction,
                'gas',
                get_buffered_gas_estimate(self.web3, transaction),
            )

        return self.web3.manager.request_blocking(
            "eth_sendTransaction",
            [transaction],
        )
Beispiel #5
0
# print('new account => {0}'.format(new_account))

accounts = w3.eth.accounts
print('accounts => {0}'.format(accounts))

balance = w3.eth.getBalance(accounts[0], 'latest')
print('balance before tx => {0}'.format(balance))

blockNumber = 0

while True:
    bn = w3.eth.blockNumber
    print('block number => {0}'.format(bn))

    transaction = {'from': accounts[0], 'to': accounts[0], 'value': 100}
    gas = get_buffered_gas_estimate(w3, transaction)
    gas_price = w3.eth.gasPrice
    # log_debug_print("use gas ", gas, "gasPrice", gas_price)
    transaction['gas'] = int(gas * 1)
    # transaction['gasPrice'] = int(gas_price * 1)

    tx_hash = w3.eth.sendTransaction(transaction)
    print('tx hash => {0}'.format(to_hex(tx_hash)))

    if bn > blockNumber:
        blockNumber = bn
        balance = w3.eth.getBalance(accounts[0], 'latest')
        print('balance after tx => {0}'.format(balance))

    time.sleep(0.2)