-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathtransfers.py
132 lines (101 loc) · 4.82 KB
/
transfers.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from web3 import Web3
from termcolor import cprint
import time
import json
import random
from tqdm import tqdm
import decimal
import requests
from tabulate import tabulate
from decimal import Decimal
from config import *
table = []
def transfer_token(privatekey, amount_to_transfer, to_address, chain_id, scan, rpc_chain, address_contract, ERC20_ABI):
try:
web3 = Web3(Web3.HTTPProvider(rpc_chain))
token_contract = web3.eth.contract(address=Web3.toChecksumAddress(address_contract), abi=ERC20_ABI)
account = web3.eth.account.privateKeyToAccount(privatekey)
address = account.address
nonce = web3.eth.getTransactionCount(address)
symbol = token_contract.functions.symbol().call()
token_decimal = token_contract.functions.decimals().call()
amount = intToDecimal(amount_to_transfer, token_decimal)
gasLimit = web3.eth.estimate_gas({'to': Web3.toChecksumAddress(address), 'from': Web3.toChecksumAddress(to_address),'value': web3.toWei(0.0001, 'ether')})
contract_txn = token_contract.functions.transfer(
Web3.toChecksumAddress(to_address),
int(amount)
).buildTransaction({
'chainId': chain_id,
'gasPrice': web3.eth.gas_price,
'gas': gasLimit+gasLimit*0.2,
'nonce': nonce,
})
tx_signed = web3.eth.account.signTransaction(contract_txn, privatekey)
tx_hash = web3.eth.sendRawTransaction(tx_signed.rawTransaction)
cprint(f'\n>>> transfer : {decimal.Decimal(str(amount_to_transfer))} {symbol} | {address} => {to_address} | {scan}/{web3.toHex(tx_hash)}', 'green')
table.append([f'{decimal.Decimal(str(amount_to_transfer))} {symbol}', address, to_address, '\u001b[32msend\u001b[0m'])
except Exception as error:
cprint(f'\n>>> transfer : {privatekey} | {error}', 'red')
try:
table.append([f'{decimal.Decimal(str(amount_to_transfer))} {symbol}', address, to_address, '\u001b[31merror\u001b[0m'])
except:
table.append([f'{symbol}', address, to_address, '\u001b[31merror\u001b[0m'])
def transfer_eth(privatekey, amount_to_transfer, to_address, chain_id, scan, rpc_chain, symbol):
try:
web3 = Web3(Web3.HTTPProvider(rpc_chain))
account = web3.eth.account.privateKeyToAccount(privatekey)
address = account.address
nonce = web3.eth.getTransactionCount(address)
amount = intToDecimal(amount_to_transfer, 18)
gasLimit = web3.eth.estimate_gas({'to': Web3.toChecksumAddress(address), 'from': Web3.toChecksumAddress(address),'value': amount})
contract_txn = {
'chainId': chain_id,
'gasPrice': web3.eth.gas_price,
'gas': gasLimit,
'nonce': nonce,
'to': Web3.toChecksumAddress(to_address),
'value': int(amount)
}
tx_signed = web3.eth.account.signTransaction(contract_txn, privatekey)
tx_hash = web3.eth.sendRawTransaction(tx_signed.rawTransaction)
cprint(f'\n>>> transfer : {decimal.Decimal(str(amount_to_transfer))} {symbol} | {address} => {to_address} | {scan}/{web3.toHex(tx_hash)}', 'green')
table.append([f'{decimal.Decimal(str(amount_to_transfer))} {symbol}', address, to_address, '\u001b[32msend\u001b[0m'])
except Exception as error:
cprint(f'\n>>> transfer : {privatekey} | {error}', 'red')
try:
table.append([f'{decimal.Decimal(str(amount_to_transfer))} {symbol}', address, to_address, '\u001b[31merror\u001b[0m'])
except:
table.append([f'{symbol}', address, to_address, '\u001b[31merror\u001b[0m'])
def transfer(privatekey, to_address, CHAIN, AMOUNT_TO_TRANSFER, ADDRESS_CONTRACT, MIN_BALANCE, MIN_AMOUNT):
data = check_rpc(CHAIN)
rpc_chain = data['rpc']
chain_id = data['chain_id']
scan = data['scan']
symbol_chain = data['token']
if ADDRESS_CONTRACT == '':
if AMOUNT_TO_TRANSFER == 'all_balance':
AMOUNT_TO_TRANSFER = check_balance(privatekey, rpc_chain, symbol_chain, MIN_BALANCE)
if AMOUNT_TO_TRANSFER > MIN_AMOUNT:
transfer_eth(
privatekey,
AMOUNT_TO_TRANSFER,
to_address,
chain_id,
scan,
rpc_chain,
symbol_chain
)
else:
if AMOUNT_TO_TRANSFER == 'all_balance':
AMOUNT_TO_TRANSFER = check_token_balance(privatekey, rpc_chain, ADDRESS_CONTRACT, MIN_BALANCE)
if AMOUNT_TO_TRANSFER > MIN_AMOUNT:
transfer_token(
privatekey,
AMOUNT_TO_TRANSFER,
to_address,
chain_id,
scan,
rpc_chain,
ADDRESS_CONTRACT,
ERC20_ABI
)