本文整理匯總了Python中web3.Web3.toChecksumAddress方法的典型用法代碼示例。如果您正苦於以下問題:Python Web3.toChecksumAddress方法的具體用法?Python Web3.toChecksumAddress怎麽用?Python Web3.toChecksumAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web3.Web3
的用法示例。
在下文中一共展示了Web3.toChecksumAddress方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def __init__(self,
contract_address,
contract_abi_string,
ethereum_chain_id,
http_provider,
websocket_provider,
gas_price_gwei,
gas_limit,
contract_owner_private_key):
super(MintableERC20Processor, self).__init__(contract_address,
contract_abi_string,
ethereum_chain_id,
http_provider,
websocket_provider,
gas_price_gwei,
gas_limit)
self.master_wallet_private_key = contract_owner_private_key
self.master_wallet_address = Web3.toChecksumAddress(utils.privtoaddr(self.master_wallet_private_key))
示例2: unify_address
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def unify_address(address: str) -> str:
'''
Returns Ethereum address with checksum.
Args:
str: Ethereum address
Returns:
str: address with checksum
Raises:
AssertionError: if the address length is incorrect
Example:
>>> from clove.network import Ethereum
>>> network = Ethereum()
>>> network.unify_address('0x999f348959e611f1e9eab2927c21e88e48e6ef45')
'0x999F348959E611F1E9eab2927c21E88E48e6Ef45'
'''
assert len(address) in (40, 42), 'Provided address is not properly formatted.'
if len(address) == 40:
address = '0x' + address
int(address, 16)
return Web3.toChecksumAddress(address)
示例3: upload_video
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def upload_video(self, video_user, password, video_file, title):
video_path = MEDIA_ROOT + '/video.mp4'
with open(video_path, 'wb+') as destination:
for chunk in video_file.chunks():
destination.write(chunk)
ipfs_add = self.ipfs_con.add(video_path)
ipfs_path = ipfs_add['Hash'].encode('utf-8')
title = title[:20].encode('utf-8')
nonce = self.w3.eth.getTransactionCount(Web3.toChecksumAddress(video_user))
txn = self.SmartContract.functions.upload_video(ipfs_path, title).buildTransaction({
'from': video_user,
'gas': 200000,
'gasPrice': self.w3.toWei('30', 'gwei'),
'nonce': nonce
})
txn_hash = self.w3.personal.sendTransaction(txn, password)
wait_for_transaction_receipt(self.w3, txn_hash)
示例4: run
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def run(self):
try:
account = w3.eth.account.privateKeyToAccount('0x'+self.private_key)
except ValueError:
QtWidgets.QMessageBox.warning(self, 'Error', 'Private key is invalid.')
return
nonce = w3.eth.getTransactionCount(Web3.toChecksumAddress(account.address))
txn = TwitterOnBlockchain.functions.write_a_tweet(self.tweet.encode('utf-8')).buildTransaction({
'from': account.address,
'gas': 70000,
'gasPrice': w3.toWei('1', 'gwei'),
'nonce': nonce
})
signed = w3.eth.account.signTransaction(txn, private_key=self.private_key)
txhash = w3.eth.sendRawTransaction(signed.rawTransaction)
wait_for_transaction_receipt(w3, txhash)
self.write_a_tweet.emit()
示例5: choose_pubaddr
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def choose_pubaddr(self):
if len(self.addresses) == 1:
address = self.addresses[0]['pubAddr']
address_i = 0
print('Using {} for this transaction.'.format(address))
else:
while True:
for i in range(0, len(self.addresses)):
print('{}\t{}\t{}\t{}'.format(
i,
self.addresses[i]['pubAddr'],
self.addresses[i]['wallet'].ljust(10),
self.addresses[i]['desc'])
)
address_i = int(input('Choose your address associated with '
'this transaction: [default: 0] ') or 0)
if not (0 <= address_i < len(self.addresses)):
print('Please choose a number between 0 and {}\n'.format(
len(self.addresses) - 1))
else:
address = Web3.toChecksumAddress(
self.addresses[address_i]['pubAddr'])
break
return address, address_i
示例6: get_token_balance
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def get_token_balance(self, account, token_addr):
"""
Returns the token balance of an account
:param account: account
:type account: str
:param token_addr: token address
:type token_addr: str
:return: balance
:rtype: int
"""
token_addr = Web3.toChecksumAddress(token_addr)
contractToken = w3.eth.contract(address=token_addr, abi=self.token_abi)
account = Web3.toChecksumAddress(account)
balance = contractToken.call().balanceOf(account)
return w3.fromWei(balance, 'ether')
示例7: get_etherdelta_token_balance
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def get_etherdelta_token_balance(self, account, token_addr):
"""
Returns the token balance in EtherDelta of an account
:param account: account
:type account: str
:param token_addr: token address
:type token_addr: str
:return: balance
:rtype: int
"""
account = Web3.toChecksumAddress(account)
balance = 0
if token_addr:
balance = self.contractEtherDelta.call().balanceOf(token=token_addr, user=account)
return w3.fromWei(balance, 'ether')
示例8: withdraw_token
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [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)
示例9: approve_deposit
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [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
示例10: hard_cancel_order
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def hard_cancel_order(self, order: List[Order]) -> str:
order_tuple: Tuple = convert_order_to_tuple(order)
# Set gas to 1, so it avoids estimateGas call in Web3, which will revert
hardCancelOrderData = self._exchange_contract.functions.cancelOrder(
order_tuple
).buildTransaction({ 'gas': 1 })
data = hardCancelOrderData['data']
self._current_gas_price = self._wallet.gas_price + 10
transaction = self._generate_signed_zero_ex_transaction(data, order['makerAddress'], self._chain_id)
tx_hash = await self._submit_coordinator_transaction(
transaction,
Web3.toChecksumAddress(order['makerAddress']),
transaction['signature'],
[],
0
)
return tx_hash
示例11: batch_hard_cancel_orders
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def batch_hard_cancel_orders(self, orders: List[Order]) -> str:
order_tuples: List[Tuple] = [convert_order_to_tuple(order) for order in orders]
makerAddress = orders[0]['makerAddress']
# Set gas to 1, so it avoids estimateGas call in Web3, which will revert
batchHardCancelOrderData = self._exchange_contract.functions.batchCancelOrders(
order_tuples
).buildTransaction({ 'gas': 1 })
data = batchHardCancelOrderData['data']
self._current_gas_price = self._wallet.gas_price + 10
transaction = self._generate_signed_zero_ex_transaction(data, makerAddress, self._chain_id)
tx_hash = await self._submit_coordinator_transaction(
transaction,
Web3.toChecksumAddress(makerAddress),
transaction['signature'],
[],
0
)
return tx_hash
示例12: download_dolomite_token_addresses
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def download_dolomite_token_addresses(token_dict: Dict[str, str]):
async with aiohttp.ClientSession() as client:
async with client.get(DOLOMITE_ENDPOINT, timeout=API_CALL_TIMEOUT) as response:
if response.status == 200:
try:
response = await response.json()
tokens = response.get("data")
for token in tokens:
asset = token["ticker"]
if asset not in token_dict:
token_dict[asset] = Web3.toChecksumAddress(token["identifier"])
elif asset == "LRC":
# Other integrations use the wrong address for LRC
token_dict[asset] = Web3.toChecksumAddress(token["identifier"])
except Exception as err:
logging.getLogger().error(err)
示例13: download_bamboo_relay_token_addresses
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def download_bamboo_relay_token_addresses(token_dict: Dict[str, str]):
page_count = 1
while True:
url = f"{BAMBOO_RELAY_ENDPOINT}?perPage=1000&page={page_count}"
async with aiohttp.ClientSession() as client:
async with client.get(url, timeout=API_CALL_TIMEOUT) as response:
page_count += 1
try:
if response.status == 200:
markets = await response.json()
if len(markets) == 0:
break
for market in markets:
market_id = market.get("id")
base, quote = market_id.split("-")
if base not in token_dict:
token_dict[base] = Web3.toChecksumAddress(market.get("baseTokenAddress"))
if quote not in token_dict:
token_dict[quote] = Web3.toChecksumAddress(market.get("quoteTokenAddress"))
else:
raise Exception(f"Call to {url} failed with status {response.status}")
except Exception as err:
logging.getLogger().error(err)
break
示例14: get_token_balance
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def get_token_balance(wallet_address, contract_address):
cs_contract_address = Web3.toChecksumAddress(contract_address)
cs_wallet_address = Web3.toChecksumAddress(wallet_address)
token = ge_w3.eth.contract(address=cs_contract_address, abi=erc20_abi.abi)
bal = token.functions.balanceOf(cs_wallet_address).call()
return bal
示例15: construct_master_wallet_approval_tasks
# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toChecksumAddress [as 別名]
def construct_master_wallet_approval_tasks(self, account_to_approve_encoded_pk, credit_transfer_id):
private_key = self.decode_private_key(account_to_approve_encoded_pk)
address = Web3.toChecksumAddress(utils.privtoaddr(private_key))
gas_required, gas_price = self.estimate_load_ether_gas_and_price()
return [
celery_tasks.load_ether.si(address, gas_required, gas_price),
celery_tasks.create_transaction_response.s(credit_transfer_id),
celery_tasks.approve_master_for_transfers.si(account_to_approve_encoded_pk, gas_required, gas_price),
celery_tasks.create_transaction_response.s(credit_transfer_id)
]