Created
September 22, 2022 10:36
-
-
Save YasunoriMATSUOKA/17c9444a01ba24f0aadb670f5e10febf to your computer and use it in GitHub Desktop.
Sample code to send transfer transaction with symbol-sdk-python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from binascii import unhexlify | |
from symbolchain.CryptoTypes import PrivateKey | |
from symbolchain.symbol.KeyPair import KeyPair | |
from symbolchain.facade.SymbolFacade import SymbolFacade | |
import datetime | |
import http.client | |
import os | |
facade = SymbolFacade('testnet') | |
b = unhexlify(os.environ['SYMBOL_SDK_PYTHON_TEST_1_PRIVATE_KEY']) | |
privateKey = PrivateKey(b) | |
keyPair = KeyPair(privateKey) | |
publicKey = keyPair.public_key | |
print(publicKey) | |
address = facade.network.public_key_to_address(publicKey) | |
print(address) | |
deadline = (int((datetime.datetime.today() + | |
datetime.timedelta(hours=2)).timestamp()) - 1637848847) * 1000 | |
tx = facade.transaction_factory.create({ | |
'type': 'transfer_transaction', | |
'signer_public_key': publicKey, | |
'fee': 100000, | |
'deadline': deadline, | |
'recipient_address': address, | |
'mosaics': [{'mosaic_id': 0x3A8416DB2D53B6C8, 'amount': 1000000}], | |
'message': bytes(1) + "test".encode('utf8') | |
}) | |
signature = facade.sign_transaction(keyPair, tx) | |
json_payload = facade.transaction_factory.attach_signature(tx, signature) | |
print(json_payload) | |
headers = {'Content-type': 'application/json'} | |
conn = http.client.HTTPConnection("sym-test-01.opening-line.jp", 3000) | |
conn.request("PUT", "/transactions", json_payload, headers) | |
response = conn.getresponse() | |
print(response.status, response.reason) | |
hash = facade.hash_transaction(tx) | |
print('http://sym-test-01.opening-line.jp:3000/transactionStatus/' + str(hash)) | |
print('https://testnet.symbol.fyi/transactions/' + str(hash)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment