Example #1
0
    def transfer(self, to, amount, gas_limit=None, gas_price=None):
        '''Transfers ether from this account.
        
        Args:
            to: Account instance or address string to transfer to.
            amount: Amount of ether to send, in wei.
            gas_limit: Gas limit of the transaction.
            gas_price: Gas price of the transaction.

        Returns:
            TransactionReceipt instance'''
        try:
            signed_tx = self._acct.signTransaction({
                'from':
                self.address,
                'nonce':
                self.nonce,
                'gasPrice':
                wei(gas_price) or self._gas_price(),
                'gas':
                wei(gas_limit) or self._gas_limit(to, amount),
                'to':
                str(to),
                'value':
                wei(amount),
                'data':
                ""
            }).rawTransaction
            txid = web3.eth.sendRawTransaction(signed_tx)
        except ValueError as e:
            txid = raise_or_return_tx(e)
        self.nonce += 1
        return TransactionReceipt(txid, self)
Example #2
0
 def _contract_tx(self, fn, args, tx, name, callback=None):
     tx['from'] = self.address
     if type(CONFIG['active_network']['gas_price']) is int:
         tx['gasPrice'] = CONFIG['active_network']['gas_price']
     if type(CONFIG['active_network']['gas_limit']) is int:
         tx['gas'] = CONFIG['active_network']['gas_limit']
     try:
         txid = fn(*args).transact(tx)
     except ValueError as e:
         txid = raise_or_return_tx(e)
     self.nonce += 1
     return TransactionReceipt(txid, self, name=name, callback=callback)
Example #3
0
 def _contract_tx(self, fn, args, tx, name, callback=None):
     try:
         tx.update({
             'from':
             self.address,
             'nonce':
             self.nonce,
             'gasPrice':
             self._gas_price(),
             'gas': (CONFIG['active_network']['gas_limit']
                     or fn(*args).estimateGas({'from': self.address}))
         })
         raw = fn(*args).buildTransaction(tx)
         txid = web3.eth.sendRawTransaction(
             self._acct.signTransaction(raw).rawTransaction)
     except ValueError as e:
         txid = raise_or_return_tx(e)
     self.nonce += 1
     return TransactionReceipt(txid, self, name=name, callback=callback)