def __new__(cls): if not hasattr(cls, 'instance'): cls.instance = super(cls, cls).__new__(cls) self = cls.instance self.client = JsonRpcClient(self.JSON_RPC_URL) return cls.instance
class XRP(object): client = None JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" # test_net def __new__(cls): if not hasattr(cls, 'instance'): cls.instance = super(cls, cls).__new__(cls) self = cls.instance self.client = JsonRpcClient(self.JSON_RPC_URL) return cls.instance def new_wallet(self) -> dict: test_wallet = generate_faucet_wallet(self.client, debug=False) return {'private_key':test_wallet.private_key,'classic_address':test_wallet.classic_address,'public_key':test_wallet.public_key ,\ 'sequence':test_wallet.sequence,'seed':test_wallet.seed } def payment(self, destination, sender, amount, sequence, seed) -> bool: my_tx_payment = Payment( account=sender, amount=xrp_to_drops(amount), destination=destination, sequence=sequence, ) sign_wallet = Wallet(seed, sequence) my_tx_payment_signed = safe_sign_and_autofill_transaction( my_tx_payment, sign_wallet, self.client) tx_response = send_reliable_submission(my_tx_payment_signed, self.client) return True def get_balance(self, sender): acct_info = AccountInfo( account=sender, ledger_index="validated", strict=True, ) response = self.client.request(acct_info) result = response.result print("response.status: ", response.status) balance = drops_to_xrp(response.result['account_data']['Balance']) print(balance) return balance
# Define the network client from xrpl.clients import JsonRpcClient JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" client = JsonRpcClient(JSON_RPC_URL) # Create a wallet using the testnet faucet: # https://xrpl.org/xrp-testnet-faucet.html from xrpl.wallet import generate_faucet_wallet test_wallet = generate_faucet_wallet(client, debug=True) # Create an account str from the wallet test_account = test_wallet.classic_address # Derive an x-address from the classic address: # https://xrpaddress.info/ from xrpl.core import addresscodec test_xaddress = addresscodec.classic_address_to_xaddress(test_account, tag=12345, is_test_network=True) print("\nClassic address:\n\n", test_account) print("X-address:\n\n", test_xaddress) # Prepare payment from xrpl.models.transactions import Payment from xrpl.utils import xrp_to_drops my_tx_payment = Payment( account=test_account, amount=xrp_to_drops(22), destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", )
"""Utility functions and variables for integration tests.""" from xrpl.clients import JsonRpcClient from xrpl.models.response import Response from xrpl.models.transactions.transaction import Transaction from xrpl.transaction import safe_sign_and_submit_transaction from xrpl.wallet import Wallet JSON_RPC_URL = "http://test.xrp.xpring.io:51234" JSON_RPC_CLIENT = JsonRpcClient(JSON_RPC_URL) def submit_transaction(transaction: Transaction, wallet: Wallet) -> Response: """Signs and submits a transaction to the XRPL.""" return safe_sign_and_submit_transaction(transaction, wallet, JSON_RPC_CLIENT)
# Define the network client from xrpl.clients import JsonRpcClient JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" client = JsonRpcClient(JSON_RPC_URL) # Create a wallet using the testnet faucet: # https://xrpl.org/xrp-testnet-faucet.html from xrpl.wallet import generate_faucet_wallet test_wallet = generate_faucet_wallet(client, debug=True) # Create an account str from the wallet test_account = test_wallet.classic_address # Derive an x-address from the classic address: # https://xrpaddress.info/ from xrpl.core import addresscodec test_xaddress = addresscodec.classic_address_to_xaddress(test_account, tag=12345, is_test_network=True) print("\nClassic address:\n\n", test_account) print("X-address:\n\n", test_xaddress) # Look up info about your account from xrpl.models.requests.account_info import AccountInfo acct_info = AccountInfo( account=test_account, ledger_index="validated", strict=True, ) response = client.request(acct_info) result = response.result