-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransfer.py
64 lines (51 loc) · 2.59 KB
/
transfer.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
import httpx
import time
from mospy import Account, Transaction
from cosmospy_protobuf.cosmos.base.v1beta1.coin_pb2 import Coin # Doğru modülden Coin import ediliyor
from cosmospy_protobuf.cosmos.bank.v1beta1.tx_pb2 import MsgSend # MsgSend import ediliyor
from tkinter import messagebox
API_URL = "https://warden-testnet-api.itrocket.net"
CHAIN_ID = "buenavista-1"
HRP = "warden"
client = httpx.Client(verify=False)
def transfer_token(target_wallet, amount, denom, fee, gas, private_key):
if private_key.startswith("0x"):
private_key = private_key[2:]
target_wallet = target_wallet.lower()
# Account oluşturulduktan sonra adresi doğru şekilde al
account = Account(private_key=private_key, hrp=HRP)
account_address = account.address # Bu satırın doğru olduğundan emin olun
print(f"Kullanılan cüzdan adresi: {account_address}") # Adresin doğru olup olmadığını kontrol edin
def fetch_account_info():
response = client.get(f"{API_URL}/cosmos/auth/v1beta1/accounts/{account_address}")
if response.status_code == 200:
account_data = response.json().get('account', {})
account.account_number = int(account_data.get('account_number', 0))
account.next_sequence = int(account_data.get('sequence', 0))
return True
else:
print(f"API'den uygun yanıt alınamadı: {account_address}, Status Code: {response.status_code}")
print("Response Body:", response.text)
return False
if not fetch_account_info():
return
tx = Transaction(account=account, gas=int(gas), chain_id=CHAIN_ID)
tx.set_fee(denom=denom, amount=str(fee))
send_msg = MsgSend(
from_address=account_address,
to_address=target_wallet,
amount=[Coin(amount=str(amount), denom=denom)]
)
tx.add_raw_msg(send_msg, type_url="/cosmos.bank.v1beta1.MsgSend")
tx_bytes = tx.get_tx_bytes_as_string()
push_url = f"{API_URL}/cosmos/tx/v1beta1/txs"
data = {"tx_bytes": tx_bytes, "mode": "BROADCAST_MODE_SYNC"}
response = client.post(push_url, json=data, headers={'Content-Type': 'application/json'})
response_data = response.json()
print(response.json())
if response_data['tx_response']['code'] == 0:
messagebox.showinfo("Transaction successful", "Transaction successful.")
return True
else:
messagebox.showerror("The operation was not successful", f"The operation was not successful: {response_data['tx_response']}")
return False