Skip to content

Commit 706aa5a

Browse files
committed
feat: added support for the new version API of web3py
1 parent 7da0cea commit 706aa5a

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

ArbitrumBridge.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def get_w3_by_network(network='mainnet'):
1616

1717
# bridge eth from rinkeby to arbitrum testnet
1818
def bridge_arbitrum_eth(w3, from_address, private_key, contract_address, amount_in_ether, chainId):
19-
from_address = Web3.toChecksumAddress(from_address)
20-
contract_address = Web3.toChecksumAddress(contract_address)
19+
from_address = Web3.to_checksum_address(from_address)
20+
contract_address = Web3.to_checksum_address(contract_address)
2121

2222
ABI = '[{"inputs":[{"internalType":"uint256","name":"maxSubmissionCost","type":"uint256"}],"name":"depositEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"}]'
2323

2424
amount_in_wei = w3.toWei(amount_in_ether, 'ether')
2525
maxSubmissionCost = int(amount_in_wei * 0.01) # 定义参数值
26-
nonce = w3.eth.getTransactionCount(from_address)
26+
nonce = w3.eth.get_transaction_count(from_address)
2727

2828
params = {
2929
'chainId': chainId,
@@ -43,7 +43,7 @@ def bridge_arbitrum_eth(w3, from_address, private_key, contract_address, amount_
4343
try:
4444
tx = func.buildTransaction(params)
4545
signed_tx = w3.eth.account.sign_transaction(tx, private_key=private_key)
46-
txn = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
46+
txn = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
4747
return {'status': 'succeed', 'txn_hash': w3.toHex(txn), 'task': 'Bridge ETH'}
4848
except Exception as e:
4949
return {'status': 'failed', 'error': e, 'task': 'Bridge ETH'}

Tutorial.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main():
2020
w3 = get_w3_by_network(network='mainnet')
2121

2222
# 检查接入状态
23-
print(w3.isConnected())
23+
print(w3.is_connected())
2424

2525
# 当前区块高度
2626
print(w3.eth.block_number)
@@ -29,7 +29,7 @@ def main():
2929
vb = '0x220866b1a2219f40e72f5c628b65d54268ca3a9d'
3030

3131
# 地址格式转换
32-
address = Web3.toChecksumAddress(vb)
32+
address = Web3.to_checksum_address(vb)
3333

3434
# 查询地址 ETH余额
3535
balance = w3.eth.get_balance(address) / 1e18

transferETH.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ def get_w3_by_network(network='mainnet'):
1414

1515

1616
def transfer_eth(w3,from_address,private_key,target_address,amount,gas_price=5,gas_limit=21000,chainId=4):
17-
from_address = Web3.toChecksumAddress(from_address)
18-
target_address = Web3.toChecksumAddress(target_address)
19-
nonce = w3.eth.getTransactionCount(from_address) # 获取 nonce 值
17+
from_address = Web3.to_checksum_address(from_address)
18+
target_address = Web3.to_checksum_address(target_address)
19+
nonce = w3.eth.get_transaction_count(from_address) # 获取 nonce 值
2020
params = {
2121
'from': from_address,
2222
'nonce': nonce,
2323
'to': target_address,
24-
'value': w3.toWei(amount, 'ether'),
24+
'value': w3.to_wei(amount, 'ether'),
2525
'gas': gas_limit,
2626
# 'gasPrice': w3.toWei(gas_price, 'gwei'),
27-
'maxFeePerGas': w3.toWei(gas_price, 'gwei'),
28-
'maxPriorityFeePerGas': w3.toWei(gas_price, 'gwei'),
27+
'maxFeePerGas': w3.to_wei(gas_price, 'gwei'),
28+
'maxPriorityFeePerGas': w3.to_wei(gas_price, 'gwei'),
2929
'chainId': chainId,
3030

3131
}
3232
try:
33-
signed_tx = w3.eth.account.signTransaction(params, private_key=private_key)
34-
txn = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
33+
signed_tx = w3.eth.account.sign_transaction(params, private_key=private_key)
34+
txn = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
3535
return {'status': 'succeed', 'txn_hash': w3.toHex(txn), 'task': 'Transfer ETH'}
3636
except Exception as e:
3737
return {'status': 'failed', 'error': e, 'task': 'Transfer ETH'}

zkSyncBridge.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def get_w3_by_network(network='goerli'):
1919

2020
# bridge eth from goerli to zkSync 2.0 testnet
2121
def bridge_zkSync_eth(w3, from_address, private_key, contract_address, amount_in_ether, chainId):
22-
from_address = Web3.toChecksumAddress(from_address)
23-
contract_address = Web3.toChecksumAddress(contract_address)
22+
from_address = Web3.to_checksum_address(from_address)
23+
contract_address = Web3.to_checksum_address(contract_address)
2424

2525
# Deposit ETH ABI
2626
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"}]'
2727

2828
amount_in_wei = w3.toWei(amount_in_ether, 'ether')
29-
nonce = w3.eth.getTransactionCount(from_address)
29+
nonce = w3.eth.get_transaction_count(from_address)
3030

3131
# goerli链:无须设置 gas, gas price , chainId, 会自动计算并配置为 EIP 1559 类型
3232
tx_params = {

0 commit comments

Comments
 (0)