This repository was archived by the owner on Jan 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionsUtils.py
More file actions
80 lines (54 loc) · 1.92 KB
/
TransactionsUtils.py
File metadata and controls
80 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from web3 import Web3
from web3.exceptions import ContractLogicError
# Definizione dell'ABI del contratto USDT
USDT_ABI = [
{
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
def WithdrawBalance(recipient_address, amount,SENDER_ADDRESS,PRIVATE_KEY):
w3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/82ef994a3a434182982d8d862117aaf4"))
USDT_ADDRESS = w3.to_checksum_address('0xdac17f958d2ee523a2206206994597c13d831ec7')
usdt_contract = w3.eth.contract(address=USDT_ADDRESS, abi=USDT_ABI)
nonce = w3.eth.get_transaction_count(SENDER_ADDRESS)
amount_wei = w3.to_wei(amount, 'ether')
recipient_address=w3.to_checksum_address(recipient_address)
# Crea la transazione
tx = {
'nonce': nonce,
'to': USDT_ADDRESS,
'value': 0,
'gas': 2000000,
'gasPrice': w3.to_wei('50', 'gwei'),
'data': usdt_contract.encodeABI(fn_name='transfer', args=[recipient_address, amount_wei]),
'chainId': 1 # Mainnet
}
# Firma la transazione con la chiave privata del wallet mittente
signed_tx = w3.eth.account.sign_transaction(tx, PRIVATE_KEY)
# Invia la transazione alla rete Ethereum
try:
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
except ContractLogicError as e:
return str(e)
return tx_hash.hex()