diff --git a/ArbitrumBridge.py b/ArbitrumBridge.py index 84662a1..ecf539f 100644 --- a/ArbitrumBridge.py +++ b/ArbitrumBridge.py @@ -16,14 +16,14 @@ def get_w3_by_network(network='mainnet'): # bridge eth from rinkeby to arbitrum testnet def bridge_arbitrum_eth(w3, from_address, private_key, contract_address, amount_in_ether, chainId): - from_address = Web3.toChecksumAddress(from_address) - contract_address = Web3.toChecksumAddress(contract_address) + from_address = Web3.to_checksum_address(from_address) + contract_address = Web3.to_checksum_address(contract_address) ABI = '[{"inputs":[{"internalType":"uint256","name":"maxSubmissionCost","type":"uint256"}],"name":"depositEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"}]' amount_in_wei = w3.toWei(amount_in_ether, 'ether') maxSubmissionCost = int(amount_in_wei * 0.01) # 定义参数值 - nonce = w3.eth.getTransactionCount(from_address) + nonce = w3.eth.get_transaction_count(from_address) params = { 'chainId': chainId, @@ -43,7 +43,7 @@ def bridge_arbitrum_eth(w3, from_address, private_key, contract_address, amount_ try: tx = func.buildTransaction(params) signed_tx = w3.eth.account.sign_transaction(tx, private_key=private_key) - txn = w3.eth.sendRawTransaction(signed_tx.rawTransaction) + txn = w3.eth.send_raw_transaction(signed_tx.rawTransaction) return {'status': 'succeed', 'txn_hash': w3.toHex(txn), 'task': 'Bridge ETH'} except Exception as e: return {'status': 'failed', 'error': e, 'task': 'Bridge ETH'} diff --git a/Tutorial.py b/Tutorial.py index dfebc86..3d123f8 100644 --- a/Tutorial.py +++ b/Tutorial.py @@ -20,7 +20,7 @@ def main(): w3 = get_w3_by_network(network='mainnet') # 检查接入状态 - print(w3.isConnected()) + print(w3.is_connected()) # 当前区块高度 print(w3.eth.block_number) @@ -29,7 +29,7 @@ def main(): vb = '0x220866b1a2219f40e72f5c628b65d54268ca3a9d' # 地址格式转换 - address = Web3.toChecksumAddress(vb) + address = Web3.to_checksum_address(vb) # 查询地址 ETH余额 balance = w3.eth.get_balance(address) / 1e18 diff --git a/transferETH.py b/transferETH.py index 8ef6d42..950e899 100644 --- a/transferETH.py +++ b/transferETH.py @@ -14,24 +14,24 @@ def get_w3_by_network(network='mainnet'): def transfer_eth(w3,from_address,private_key,target_address,amount,gas_price=5,gas_limit=21000,chainId=4): - from_address = Web3.toChecksumAddress(from_address) - target_address = Web3.toChecksumAddress(target_address) - nonce = w3.eth.getTransactionCount(from_address) # 获取 nonce 值 + from_address = Web3.to_checksum_address(from_address) + target_address = Web3.to_checksum_address(target_address) + nonce = w3.eth.get_transaction_count(from_address) # 获取 nonce 值 params = { 'from': from_address, 'nonce': nonce, 'to': target_address, - 'value': w3.toWei(amount, 'ether'), + 'value': w3.to_wei(amount, 'ether'), 'gas': gas_limit, # 'gasPrice': w3.toWei(gas_price, 'gwei'), - 'maxFeePerGas': w3.toWei(gas_price, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(gas_price, 'gwei'), + 'maxFeePerGas': w3.to_wei(gas_price, 'gwei'), + 'maxPriorityFeePerGas': w3.to_wei(gas_price, 'gwei'), 'chainId': chainId, } try: - signed_tx = w3.eth.account.signTransaction(params, private_key=private_key) - txn = w3.eth.sendRawTransaction(signed_tx.rawTransaction) + signed_tx = w3.eth.account.sign_transaction(params, private_key=private_key) + txn = w3.eth.send_raw_transaction(signed_tx.rawTransaction) return {'status': 'succeed', 'txn_hash': w3.toHex(txn), 'task': 'Transfer ETH'} except Exception as e: return {'status': 'failed', 'error': e, 'task': 'Transfer ETH'} diff --git a/zkSyncBridge.py b/zkSyncBridge.py index 882371e..e508aff 100644 --- a/zkSyncBridge.py +++ b/zkSyncBridge.py @@ -19,14 +19,14 @@ def get_w3_by_network(network='goerli'): # bridge eth from goerli to zkSync 2.0 testnet def bridge_zkSync_eth(w3, from_address, private_key, contract_address, amount_in_ether, chainId): - from_address = Web3.toChecksumAddress(from_address) - contract_address = Web3.toChecksumAddress(contract_address) + from_address = Web3.to_checksum_address(from_address) + contract_address = Web3.to_checksum_address(contract_address) # Deposit ETH ABI ABI = '[{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_zkSyncAddress","type":"address"},{"internalType":"enum Operations.QueueType","name":"_queueType","type":"uint8"},{"internalType":"enum Operations.OpTree","name":"_opTree","type":"uint8"}],"name":"depositETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"emergencyFreezeDiamond","outputs":[],"stateMutability":"nonpayable","type":"function"}]' amount_in_wei = w3.toWei(amount_in_ether, 'ether') - nonce = w3.eth.getTransactionCount(from_address) + nonce = w3.eth.get_transaction_count(from_address) # goerli链:无须设置 gas, gas price , chainId, 会自动计算并配置为 EIP 1559 类型 tx_params = {