-
Notifications
You must be signed in to change notification settings - Fork 4
/
example2.py
47 lines (39 loc) · 1.14 KB
/
example2.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
import time
from loguru import logger
from aptc import Account, APT, new_client
# init logger
logger.add("example2.log")
client = new_client()
# submit transaction
# load your private key
account = Account.load_key("")
account_address = account.address()
# build a transaction payload
payload = {
'function': '0x1::aptos_account::transfer',
'type_arguments': [],
'arguments': [
"0x8d763223180a2b92f97755a3ea581f1c68d342275ca6118badff663f57aca7a5", # receiver
str(1 * APT) # amount
],
'type': 'entry_function_payload'
}
txn_dict = {
"sender": f"{account_address}",
"sequence_number": str(client.get_account_sequence_number(account_address)),
"max_gas_amount": str(100_000),
"gas_unit_price": str(100),
"expiration_timestamp_secs": str(int(time.time()) + 100),
"payload": payload,
}
# encode this transaction
encoded = client.encode(txn_dict)
# sign this transaction
signature = account.sign(encoded)
txn_dict["signature"] = {
"type": "ed25519_signature",
"public_key": f"{account.public_key()}",
"signature": f"{signature}",
}
# submit transaction
tx = client.submit_transaction(txn_dict)