当前位置: 首页>>代码示例>>Python>>正文


Python Web3.toWei方法代码示例

本文整理汇总了Python中web3.Web3.toWei方法的典型用法代码示例。如果您正苦于以下问题:Python Web3.toWei方法的具体用法?Python Web3.toWei怎么用?Python Web3.toWei使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在web3.Web3的用法示例。


在下文中一共展示了Web3.toWei方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_token_calculate_payment

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def test_token_calculate_payment(self):
        token = TokenFactory(fixed_eth_conversion=0.1)
        self.assertEqual(token.calculate_payment(Web3.toWei(1, 'ether')), Web3.toWei(10, 'ether'))

        token = TokenFactory(fixed_eth_conversion=1.0)
        self.assertEqual(token.calculate_payment(Web3.toWei(1, 'ether')), Web3.toWei(1, 'ether'))

        token = TokenFactory(fixed_eth_conversion=2.0)
        self.assertEqual(token.calculate_payment(Web3.toWei(1, 'ether')), Web3.toWei(0.5, 'ether'))

        token = TokenFactory(fixed_eth_conversion=10.0)
        self.assertEqual(token.calculate_payment(Web3.toWei(1, 'ether')), Web3.toWei(0.1, 'ether'))

        token = TokenFactory(fixed_eth_conversion=0.6512)
        self.assertEqual(token.calculate_payment(Web3.toWei(1.23, 'ether')), 1888820638820638720)

        token = TokenFactory(fixed_eth_conversion=1.0, decimals=17)
        self.assertEqual(token.calculate_payment(Web3.toWei(1, 'ether')), Web3.toWei(0.1, 'ether')) 
开发者ID:gnosis,项目名称:safe-relay-service,代码行数:20,代码来源:test_models.py

示例2: withdraw_token

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def withdraw_token(self, tokenaddress, amount, user_private_key):
        """
        Invokes on-chain withdraw tokens. Only apply for 18 decimal tokens
        :param tokenaddress: withdraw contract address
        :type order: string
        :param amount: withdraw token amount
        :type amount: float
        :param user_private_key: user private key
        :type user_private_key: string
        :return: tx
        :rtype: object
        """

        amount_in_wei = Web3.toWei(amount, 'ether')
        kwargs = {
            'token' : Web3.toChecksumAddress(tokenaddress),
            'amount' : int(Decimal(amount_in_wei)),
        }
        self.__send_transaction(self, "withdrawToken", kwargs, user_private_key) 
开发者ID:CoinCircle,项目名称:py-etherdelta,代码行数:21,代码来源:__init__.py

示例3: __init__

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def __init__(self,
                     contract_address,
                     contract_abi_string,
                     ethereum_chain_id,
                     http_provider,
                     websocket_provider,
                     gas_price_gwei,
                     gas_limit,):

            self.abi_dict = json.loads(contract_abi_string)
            self.contract_address = utils.checksum_encode(contract_address)
            self.ethereum_chain_id = int(ethereum_chain_id)

            self.w3 = Web3(HTTPProvider(http_provider))
            # self.wsw3 = Web3(WebsocketProvider(websocket_provider))

            self.contract = self.w3.eth.contract(address=self.contract_address, abi=self.abi_dict)
            self.decimals = self.get_decimals()

            self.gas_price = self.w3.toWei(gas_price_gwei, 'gwei')
            self.gas_limit = gas_limit
            self.transaction_max_value = self.gas_price * self.gas_limit 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:24,代码来源:ethereum_processor.py

示例4: value_to_base_units

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def value_to_base_units(value: float) -> int:
        '''
        Converting value to base units.

        Args:
            value (int): value in main coins (Ethereum)

        Returns:
            float: value in base units (Wei)

        Example:
            >>> from clove.network import Ethereum
            >>> network = Ethereum()
            >>> network.value_to_base_units(0.00000001)
            10000000000
        '''
        return Web3.toWei(value, 'ether') 
开发者ID:Lamden,项目名称:clove,代码行数:19,代码来源:base.py

示例5: withdraw

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def withdraw(self, amount, user_private_key):
        """
        Invokes on-chain withdraw ether
        :param amount: withdraw ether amount
        :type amount: float
        :param user_private_key: user private key
        :type user_private_key: string
        :return: tx
        :rtype: object
        """

        amount_in_wei = Web3.toWei(amount, 'ether')
        kwargs = {
            'amount' : int(Decimal(amount_in_wei)),
        }
        return self.__send_transaction("withdraw", kwargs, user_private_key) 
开发者ID:CoinCircle,项目名称:py-etherdelta,代码行数:18,代码来源:__init__.py

示例6: approve_deposit

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def approve_deposit(self, tokenaddress, amount, user_private_key):
        global web3, addressEtherDelta
        maxGas = 250000
        gasPriceWei = 4000000000    # 1 Gwei

        amount_in_wei = Web3.toWei(amount, 'ether')
        kwargs = {
            '_spender' : Web3.toChecksumAddress(addressEtherDelta),
            '_value' : int(Decimal(amount_in_wei)),
        }

        userAccount = w3.eth.account.privateKeyToAccount(user_private_key).address
        # Bail if there's no private key
        if len(user_private_key) != 64: raise ValueError('WARNING: user_private_key must be a hexadecimal string of 64 characters long')
        # Build binary representation of the function call with arguments
        token_contract = w3.eth.contract(address=Web3.toChecksumAddress(tokenaddress), abi=self.token_abi)
        abidata = token_contract.encodeABI("approve", kwargs=kwargs)
        nonce = w3.eth.getTransactionCount(userAccount)
        transaction = { 'to': Web3.toChecksumAddress(tokenaddress), 'from': userAccount, 'gas': maxGas, 'gasPrice': gasPriceWei, 'data': abidata, 'nonce': nonce, 'chainId': 1}
        print(transaction)
        signed = w3.eth.account.signTransaction(transaction, user_private_key)
        result = w3.eth.sendRawTransaction(w3.toHex(signed.rawTransaction))
        print("Transaction returned: " + str(result))
        print("\nDone! You should see the transaction show up at https://etherscan.io/tx/" + w3.toHex(result))
        return result, nonce 
开发者ID:CoinCircle,项目名称:py-etherdelta,代码行数:27,代码来源:__init__.py

示例7: make_disbursement

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def make_disbursement(self,
                          transfer_amount,
                          recipient_address,
                          account_to_approve_encoded_pk,
                          master_wallet_approval_status,
                          uncompleted_tasks,
                          is_retry,
                          credit_transfer_id=None):

        chain_list = []

        approval_required = self.determine_if_master_wallet_approval_required(
            master_wallet_approval_status,
            uncompleted_tasks,
            is_retry)

        if approval_required:
            chain_list.extend(
                self.construct_master_wallet_approval_tasks(
                    account_to_approve_encoded_pk,
                    credit_transfer_id)
            )

        if not is_retry or 'disbursement' in uncompleted_tasks:
            chain_list.extend([
                celery_tasks.disburse_funds.si(transfer_amount, recipient_address, credit_transfer_id),
                celery_tasks.create_transaction_response.s(credit_transfer_id)
            ])


        if not is_retry or 'ether load' in uncompleted_tasks:
            if float(self.force_eth_disbursement_amount or 0) > 0:

                forced_amount_wei = Web3.toWei(self.force_eth_disbursement_amount, 'ether')

                chain_list.extend([
                    celery_tasks.load_ether.si(recipient_address, forced_amount_wei, 1),
                    celery_tasks.create_transaction_response.s(credit_transfer_id)
                ])

        chain(chain_list).on_error(celery_tasks.log_error.s(credit_transfer_id)).delay() 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:43,代码来源:ethereum_processor.py

示例8: __init__

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def __init__(self, gas_price: Optional[int] = None):
        if gas_price is None:
            self.lowest = Web3.toWei(1, 'gwei')
            self.safe_low = Web3.toWei(5, 'gwei')
            self.standard = Web3.toWei(10, 'gwei')
            self.fast = Web3.toWei(20, 'gwei')
            self.fastest = Web3.toWei(50, 'gwei')
        else:
            self.lowest = Web3.toWei(gas_price, 'gwei')
            self.safe_low = Web3.toWei(gas_price + 1, 'gwei')
            self.standard = Web3.toWei(gas_price + 2, 'gwei')
            self.fast = Web3.toWei(gas_price + 3, 'gwei')
            self.fastest = Web3.toWei(gas_price + 4, 'gwei') 
开发者ID:gnosis,项目名称:safe-relay-service,代码行数:15,代码来源:gas_station.py

示例9: send_eth_to

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def send_eth_to(self, to: str, value: int, gas: int = 22000, gas_price=None,
                    retry: bool = False, block_identifier='pending'):
        if not gas_price:
            gas_price = self.gas_station.get_gas_prices().standard

        if self.max_eth_to_send and value > Web3.toWei(self.max_eth_to_send, 'ether'):
            raise EtherLimitExceeded('%d is bigger than %f' % (value, self.max_eth_to_send))

        with EthereumNonceLock(self.redis, self.ethereum_client, self.funder_account.address,
                               lock_timeout=60 * 2) as tx_nonce:
            return self.ethereum_client.send_eth_to(self.funder_account.key, to, gas_price, value,
                                                    gas=gas,
                                                    retry=retry,
                                                    block_identifier=block_identifier,
                                                    nonce=tx_nonce) 
开发者ID:gnosis,项目名称:safe-relay-service,代码行数:17,代码来源:funding_service.py

示例10: setUp

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def setUp(self):
        self.env = Env(b"", caller=utils.DEFAULT_CALLER, address=utils.DEFAULT_ADDRESS)

        self.state = State(self.env)
        self.analyzer = Analyzer(
            address=self.env.address,
            caller=self.env.caller,
            max_wei_to_send=Web3.toWei(10, "ether"),
            min_wei_to_receive=Web3.toWei(1, "milliether"),
        ) 
开发者ID:palkeo,项目名称:pakala,代码行数:12,代码来源:test_analyzer.py

示例11: test_send_back_more

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def test_send_back_more(self):
        self.state.calls.append(self.get_call(self.env.value + Web3.toWei(1, "ether")))
        self.assertTrue(self.check_state(self.state)) 
开发者ID:palkeo,项目名称:pakala,代码行数:5,代码来源:test_analyzer.py

示例12: test_send_back_if_impossible_block

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def test_send_back_if_impossible_block(self):
        self.state.calls.append(
            self.get_call(
                claripy.If(
                    self.env.block_number > 100000000000,
                    self.env.value + Web3.toWei(1, "ether"),
                    0,
                )
            )
        )
        self.assertFalse(self.check_state(self.state)) 
开发者ID:palkeo,项目名称:pakala,代码行数:13,代码来源:test_analyzer.py

示例13: test_send_back_if_possible_block

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def test_send_back_if_possible_block(self):
        self.state.calls.append(
            self.get_call(
                claripy.If(
                    self.env.block_number < 100000000000,
                    self.env.value + Web3.toWei(1, "ether"),
                    0,
                )
            )
        )
        self.assertTrue(self.check_state(self.state)) 
开发者ID:palkeo,项目名称:pakala,代码行数:13,代码来源:test_analyzer.py

示例14: test_send_back_fixed_amount

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def test_send_back_fixed_amount(self):
        self.state.calls.append(self.get_call(Web3.toWei(1, "ether")))
        self.assertTrue(self.check_state(self.state)) 
开发者ID:palkeo,项目名称:pakala,代码行数:5,代码来源:test_analyzer.py

示例15: test_read_concrete

# 需要导入模块: from web3 import Web3 [as 别名]
# 或者: from web3.Web3 import toWei [as 别名]
def test_read_concrete(self):
        self.analyzer.actual_storage = {0: 0xBAD1DEA}

        self.state.storage_read[utils.bvv(0)] = claripy.BVS("storage[0]", 256)
        self.state.selfdestruct_to = self.state.storage_read[utils.bvv(0)]
        self.assertFalse(self.check_state(self.state))

        self.state.calls.append(
            self.get_call(
                Web3.toWei(1, "ether") * self.state.storage_read[utils.bvv(0)]
            )
        )
        self.assertTrue(self.check_state(self.state)) 
开发者ID:palkeo,项目名称:pakala,代码行数:15,代码来源:test_analyzer.py


注:本文中的web3.Web3.toWei方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。