ApiClientExample
1 min
Code block
import json
from typing import Optional, Union
from ApiClient import ApiClient
class ApiClientExamples:
class Symbols:
bitcoin = "BTC"
ethereum = "ETH"
bitcoin_cash = "BCH"
ripple = "XRP"
stellar = "XLM"
cardano = "ADA"
tezos = "XTZ"
near = "NEAR"
hedera = "HBAR"
iota = "MIOTA"
shimmer = "SMR"
class Amounts:
BTC = "60000000"
ETH = "6000"
BCH = "6000"
XRP = "6000"
XLM = "6000"
ADA = "1000000"
XTZ = "6000"
NEAR = "6000"
HBAR = "6000"
MIOTA = "2000000"
SMR = "2000000"
class Fees:
BTC = 10
ETH = 3000000000
BCH = 5
XRP = 20
XLM = 100
ADA = 44
XTZ = 1
def __init__(self, qrPath: Optional[str] = None):
path = "../example_qr.txt"
if qrPath is not None:
path = qrPath
self.apiUser = ApiClient.fromQr(path, "1.1.1.11")
self.apiUser.generateNewAccessToken()
# --------------------------- Transaction Information: ---------------------------------------
def sendTransaction(self, coins: Optional[list] = None):
addr = json.dumps(self.apiUser.getAccounts())
addresses = json.loads(addr)
addrBTC = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][0]["ColdAddress"]
addrETH = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][1]["ColdAddress"]
addrBCH = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][2]["ColdAddress"]
addrXRP = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][3]["ColdAddress"]
addrXLM = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][4]["ColdAddress"]
addrADA = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][5]["ColdAddress"]
addrXTZ = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][6]["ColdAddress"]
addrNEAR = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][7]["ColdAddress"]
addrHBAR = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][8]["ColdAddress"]
addrMIOTA = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][9]["ColdAddress"]
addrSMR = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][10]["ColdAddress"]
if coins is None:
coins = ["BTC", "ETH", "BCH", "XRP", "XLM", "ADA", "XTZ", "NEAR", "MIOTA", "SMR"]
# BTC:
if "BTC" in coins:
self.apiUser.sendTransaction(1, self.Symbols.bitcoin, [(addrBTC, self.Amounts.BTC)], self.Fees.BTC, None,
False)
# ETH:
# if "ETH" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.ethereum, [(addrETH, self.Amounts.ETH)], self.Fees.ETH, 21000,
# False)
# # BCH:
# if "BCH" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.bitcoin_cash, [(addrBCH, self.Amounts.BCH)], self.Fees.BCH,
# None, False)
# # XRP:
# if "XRP" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.ripple, [(addrXRP, self.Amounts.XRP, 1)], self.Fees.XRP, None,
# False)
# # Stellar:
# if "XLM" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.stellar, [(addrXLM, self.Amounts.XLM)], self.Fees.XLM, None,
# False)
# # Cardano:
# if "ADA" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.cardano, [(addrADA, self.Amounts.ADA)], self.Fees.ADA, None,
# False)
# # TEZOS:
# if "XTZ" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.tezos, [(addrXTZ, self.Amounts.XTZ)], self.Fees.XTZ, 1451,
# False, storage_limit=257)
# # NEAR:
# if "NEAR" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.near, [(addrNEAR, self.Amounts.NEAR)])
#
# # MIOTA:
# if "MIOTA" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.iota, [(addrMIOTA, self.Amounts.MIOTA)])
#
# # SMR:
# if "SMR" in coins:
# self.apiUser.sendTransaction(1, self.Symbols.shimmer, [(addrSMR, self.Amounts.SMR)])
def getTransactionData(self):
order_from_newest: str = "false"
# BTC:
self.apiUser.getTransactionData(1, self.Symbols.bitcoin, order_from_newest)
# ETH:
self.apiUser.getTransactionData(1, self.Symbols.ethereum, order_from_newest)
# BCH:
self.apiUser.getTransactionData(1, self.Symbols.bitcoin_cash, order_from_newest)
# XRP:
self.apiUser.getTransactionData(1, self.Symbols.ripple, order_from_newest)
# XLM:
self.apiUser.getTransactionData(1, self.Symbols.stellar, order_from_newest)
def getConfirmations(self):
# BTC:
self.apiUser.getConfirmations(self.Symbols.bitcoin)
# ETH:
self.apiUser.getConfirmations(self.Symbols.ethereum)
# BCH:
self.apiUser.getConfirmations(self.Symbols.bitcoin_cash)
# XRP:
self.apiUser.getConfirmations(self.Symbols.ripple)
# XLM:
self.apiUser.getConfirmations(self.Symbols.stellar)
def statusForTransaction(self):
tx_token = ""
# BTC:
self.apiUser.statusForTransaction(tx_token, self.Symbols.bitcoin)
# ETH:
self.apiUser.statusForTransaction(tx_token, self.Symbols.ethereum)
# BCH:
self.apiUser.statusForTransaction(tx_token, self.Symbols.bitcoin_cash)
# XRP:
self.apiUser.statusForTransaction(tx_token, self.Symbols.ripple)
# XLM:
self.apiUser.statusForTransaction(tx_token, self.Symbols.stellar)
def getSingleTransaction(self):
tx_token = ""
# BTC:
self.apiUser.getSingleTransaction(tx_token, self.Symbols.bitcoin)
# ETH:
self.apiUser.getSingleTransaction(tx_token, self.Symbols.ethereum)
# BCH:
self.apiUser.getSingleTransaction(tx_token, self.Symbols.bitcoin_cash)
# XRP:
self.apiUser.getSingleTransaction(tx_token, self.Symbols.ripple)
# XLM:
self.apiUser.getSingleTransaction(tx_token, self.Symbols.stellar)
# --------------------------- End Transaction Information: ---------------------------------------
# --------------------------- Wallet Information: ---------------------------------------
def getCoins(self):
self.apiUser.getAccounts()
def getSystemPreferences(self):
self.apiUser.getSystemPreferences()
def getAccounts(self):
self.apiUser.getAccounts()
def getFundsForAddress(self):
addr = json.dumps(self.apiUser.getAccounts())
addresses = json.loads(addr)
addrBTC = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][0]["HotAddress"]
addrETH = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][1]["HotAddress"]
addrBCH = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][2]["HotAddress"]
addrXRP = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][3]["HotAddress"]
addrGNT = addresses["FunctionData"]["Accounts"][0]["AccountDataSignedByCold"]["Addresses"][4]["HotAddress"]
# BTC:
self.apiUser.getFundsForAddress(1, addrBTC, self.Symbols.bitcoin)
# ETH:
self.apiUser.getFundsForAddress(1, addrETH, self.Symbols.ethereum)
# BCH:
self.apiUser.getFundsForAddress(1, addrBCH, self.Symbols.bitcoin_cash)
# XRP:
self.apiUser.getFundsForAddress(1, addrXRP, self.Symbols.ripple)
# XLM:
self.apiUser.getFundsForAddress(1, addrGNT, self.Symbols.stellar)
def availableBalance(self):
# BTC:
self.apiUser.availableBalance(1, [self.Symbols.bitcoin])
# ETH:
self.apiUser.availableBalance(1, [self.Symbols.ethereum])
# BCH:
self.apiUser.availableBalance(1, [self.Symbols.bitcoin_cash])
# XRP:
self.apiUser.availableBalance(1, [self.Symbols.ripple])
# XLM:
self.apiUser.availableBalance(1, [self.Symbols.stellar])
def isSupportSendToMany(self):
# BTC:
self.apiUser.isSupportSendToMany(self.Symbols.bitcoin)
# ETH:
self.apiUser.isSupportSendToMany(self.Symbols.ethereum)
# BCH:
self.apiUser.isSupportSendToMany(self.Symbols.bitcoin_cash)
# XRP:
self.apiUser.isSupportSendToMany(self.Symbols.ripple)
# XLM:
self.apiUser.isSupportSendToMany(self.Symbols.stellar)
def get_user_identifier(self):
self.apiUser.get_user_identifier()
def get_is_SSM(self):
self.apiUser.get_is_SSM()
# --------------------------- End Wallet Information: ---------------------------------------
# --------------------------- Bulletins: ---------------------------------------
def getBulletins(self):
# will auto decrypt decrypt notifications
self.apiUser.getBulletins(True)
# will not auto decrypt decrypt notifications
self.apiUser.getBulletins()
def getColdTransactionBulletins(self):
# get all bulletins for cold wallet
self.apiUser.getColdTransactionBulletins()
# get 100 approval pending bulletins for cold wallet
# self.apiUser.getColdTransactionBulletins(0,100, True)
def approveHotRequest(self):
hot_tx_bulletins = self.apiUser.getBulletins()
if not hot_tx_bulletins["FunctionData"]["Bulletins"]:
return None
for index, bulletin in enumerate(hot_tx_bulletins["FunctionData"]["Bulletins"]):
if bulletin["Description"]["Machine"] == "HOT":
if bulletin["Description"]["Status"] == 0:
request_id: str = bulletin["Header"]["ID"]
request_creator_id: str = bulletin["Header"]["Creator"]
request_creator_name: str = bulletin["Header"]["CreatorName"]
request_type: int = bulletin["Header"]["Type"]
outputs: list = bulletin["Description"].get("Outputs", "")
txAccessToken: str = bulletin["Description"]["TxAccessToken"]
accountId: int = int(bulletin["Description"]["AccountId"])
currencySymbol: str = bulletin["Description"]["CurrencySymbol"]
approvers_list: list = bulletin["Header"]["UserActions"]
specific = bulletin["Description"].get("SpecificFromAddress", "")
bytes_to_sign = ""
data_to_sign = None
if "StellarRawBytesRequest" in bulletin["Description"]:
bytes_to_sign = bulletin["Description"]["StellarRawBytesRequest"]
elif "NearRawBytesRequest" in bulletin["Description"]:
bytes_to_sign = bulletin["Description"]["NearRawBytesRequest"]
elif "DataToSign" in bulletin["Description"]:
data_to_sign = bulletin["Description"]["DataToSign"]
data_for_contract_from_bulletin = None
if "DataForContract" in bulletin["Description"]:
data_for_contract_from_bulletin = bulletin["Description"]["DataForContract"]
data_for_contract_for_approve_request = None
if data_for_contract_from_bulletin is not None:
if "DataForContractAsHex" in data_for_contract_from_bulletin:
data_for_contract_for_approve_request = {
"RawData": data_for_contract_from_bulletin["DataForContractAsHex"]}
else:
data_for_contract_for_approve_request = {
"FunctionName": data_for_contract_from_bulletin["FunctionName"]}
# data_for_contract_function_data: dict | list
data_for_contract_function_data: Union[dict, list]
if currencySymbol == "XTZ":
data_for_contract_function_data = {}
if "FunctionData" in data_for_contract_from_bulletin:
data_for_contract_for_approve_request["Parameters"] = \
data_for_contract_from_bulletin["FunctionData"][0]["Value"]
else: # EVM contracts
data_for_contract_function_data = []
if "FunctionData" in data_for_contract_from_bulletin:
for type_and_value in data_for_contract_from_bulletin["FunctionData"]:
data_for_contract_function_data.append(
[type_and_value["Key"], type_and_value["Value"]])
data_for_contract_for_approve_request[
"ParametersFieldsTypesAndValues"] = data_for_contract_function_data
is_eth1_to_eth2_conversion = None
if "IsEth1ToEth2Conversion" in bulletin["Description"]:
is_eth1_to_eth2_conversion = bulletin["Description"]["IsEth1ToEth2Conversion"]
self.apiUser.approveHotRequest(request_id, request_creator_id, request_creator_name, request_type,
currencySymbol, accountId, outputs, txAccessToken, approvers_list,
specific_from_address=specific,
data_for_contract=data_for_contract_for_approve_request,
is_eth1_to_eth2_conversion=is_eth1_to_eth2_conversion,
bytes_to_sign=bytes_to_sign, data_to_sign=data_to_sign)
return 1
print("No HOT transactions left to approve!")
def approveColdRequest(self):
cold_tx_bulletins = self.apiUser.getColdTransactionBulletins(0, 100, True)
if not cold_tx_bulletins:
print("No COLD transactions left to approve!")
return None
print(cold_tx_bulletins)
json_cold_tx_bulletins0 = cold_tx_bulletins[0]["TransactionRequest"]
json_cold_tx_bulletins1 = cold_tx_bulletins[0]["TransactionCryptography"]
request_id: str = json_cold_tx_bulletins0["RequestId"]
request_creator_id: str = json_cold_tx_bulletins1["Question"]["Creator"]["ID"]
request_creator_name: str = json_cold_tx_bulletins1["Question"]["Creator"]["Email"]
request_type: int = json_cold_tx_bulletins0["Type"]
outputs: list = []
approvers_list: list = json_cold_tx_bulletins0["UserActions"]
a_index: str = json_cold_tx_bulletins1["Answers"]["Approve"]["Index"]
a_share: str = json_cold_tx_bulletins1["Answers"]["Approve"]["Share"]
a_random: str = json_cold_tx_bulletins1["Answers"]["Approve"]["Random"]
self.apiUser.approveColdRequest(request_id, request_creator_id, request_creator_name, request_type, outputs,
approvers_list, a_index, a_share, a_random)
# --------------------------- End Bulletins: ---------------------------------------
# --------------------------- Other Functions: ---------------------------------------
def getSuggestedFee(self, use_cache="true"):
# BTC:
self.apiUser.getSuggestedFee(use_cache, [self.Symbols.bitcoin])
# ETH:
self.apiUser.getSuggestedFee(use_cache, [self.Symbols.ethereum])
# BCH:
self.apiUser.getSuggestedFee(use_cache, [self.Symbols.bitcoin_cash])
# XRP:
self.apiUser.getSuggestedFee(use_cache, [self.Symbols.ripple])
# XLM:
self.apiUser.getSuggestedFee(use_cache, [self.Symbols.stellar])
# OR:
self.apiUser.getSuggestedFee(use_cache, ["ALL_COINS"])
def getCommunityWithLastSeen(self):
self.apiUser.getCommunityWithLastSeen()
# --------------------------- End Other Functions: ---------------------------------------
from Helpers.AddressesDerivation import AddressesDerivation
if __name__ == "__main__":
apiClientExamples = ApiClientExamples()
# apiClientExamples.sendTransaction(["BTC"])
apiClientExamples.approveHotRequest()