diff --git a/content/_code-samples/delete-account/js/blackhole-account.js b/content/_code-samples/delete-account/js/blackhole-account.js new file mode 100644 index 0000000000..2df280fe42 --- /dev/null +++ b/content/_code-samples/delete-account/js/blackhole-account.js @@ -0,0 +1,68 @@ +if (typeof module !== "undefined") { + // Use var here because const/let are block-scoped to the if statement. + var xrpl = require('xrpl') + } + // Blackhole an account. + // For some addresses, it's possible that no one has the secret key, in which case the account is a black hole and the XRP is lost forever. + // https://xrpl.org/accounts.html#special-addresses + // https://xrpl.org/disable-master-key-pair.html#disable-master-key-pair + + async function main() { + // Connect to a testnet node + console.log("Connecting to Testnet...") + const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233') + await client.connect() + + // Get account credentials from the Testnet Faucet + console.log("Requesting an account from the Testnet faucet...") + const { wallet, balance } = await client.fundWallet() + + console.log("\nAccount: ", wallet.address) + console.log(" Seed: ", wallet.seed) + + // This is a well known blackhole address + const blackhole_address = "rrrrrrrrrrrrrrrrrrrrBZbvji" + + // Send AccountSet transaction + const SetRegularKey_tx = await client.autofill({ + "TransactionType": "SetRegularKey", + "Account": wallet.address, + "RegularKey": blackhole_address + }) + + const SetRegularKey_tx_signed = wallet.sign(SetRegularKey_tx) + const SetRegularKey_tx_result = await client.submitAndWait(SetRegularKey_tx_signed.tx_blob) + + console.log(`\n Submitted a SetRegularKey transaction (Result: ${SetRegularKey_tx_result.result.meta.TransactionResult})`) + console.log(` Transaction hash: ${SetRegularKey_tx_signed.hash}`) + + // Send AccountSet transaction + const DisableMasterKey_tx = await client.autofill({ + "TransactionType": "AccountSet", + "Account": wallet.address, + "SetFlag": xrpl.AccountSetAsfFlags.asfDisableMaster + }) + + const DisableMasterKey_tx_signed = wallet.sign(DisableMasterKey_tx) + const DisableMasterKey_tx_result = await client.submitAndWait(DisableMasterKey_tx_signed.tx_blob) + + console.log(`\n Submitted a DisableMasterKey transaction (Result: ${DisableMasterKey_tx_result.result.meta.TransactionResult}`) + console.log(` Transaction hash: ${DisableMasterKey_tx_signed.hash}`) + + const response = await client.request({ + "command": "account_info", + "account": wallet.address, + "ledger_index": "validated" + }) + + if (response.result.account_data.Flags == 1114112) { + console.log(`\nAccount ${wallet.address}'s master key has been disabled, the account is now blackholed.`) + } else { + console.log(`\nAccount ${wallet.address}'s master key is still enabled, account is NOT blackholed.`) + } + + client.disconnect() + // End main() + } + + main() diff --git a/content/_code-samples/delete-account/py/blackhole-account.py b/content/_code-samples/delete-account/py/blackhole-account.py new file mode 100644 index 0000000000..eb88b61c14 --- /dev/null +++ b/content/_code-samples/delete-account/py/blackhole-account.py @@ -0,0 +1,65 @@ +from xrpl.clients import JsonRpcClient +from xrpl.models.transactions import AccountSet, SetRegularKey, AccountSetFlag, Payment +from xrpl.transaction import safe_sign_and_autofill_transaction, send_reliable_submission +from xrpl.wallet import generate_faucet_wallet +from xrpl.models.requests import AccountInfo + +# This code sample will blackhole an account +# A funded account on the testnet is provided for testing purposes +# https://xrpl.org/accounts.html#special-addresses + +asfDisableMaster = 1114112 + +# Connect to a testnet node +JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/" +client = JsonRpcClient(JSON_RPC_URL) + +# Get credentials from the Testnet Faucet +print("Requesting an account from the Testnet faucet...") +test_wallet = generate_faucet_wallet(client=client) +myAddr = test_wallet.classic_address + +print(f"\n Account: {test_wallet.classic_address}") +print(f" Seed: {test_wallet.seed}") + +# This is a well known blackhole address +blackhole_address = "rrrrrrrrrrrrrrrrrrrrBZbvji" + +# Construct SetRegularKey transaction +tx_regulary_key = SetRegularKey( + account=myAddr, + regular_key=blackhole_address +) + +# Sign the transaction +tx_regulary_key_signed = safe_sign_and_autofill_transaction(tx_regulary_key, wallet=test_wallet, client=client) +submit_tx_regular = send_reliable_submission(client=client, transaction=tx_regulary_key_signed) +submit_tx_regular = submit_tx_regular.result +print(f"\n Submitted a SetRegularKey tx. Result: {submit_tx_regular['meta']['TransactionResult']}") +print(f" Tx content: {submit_tx_regular}") + +# Construct AccountSet transaction w/ asfDisableMaster flag +# This permanently blackholes an account! +tx_disable_master_key = AccountSet( + account=myAddr, + set_flag=AccountSetFlag.ASF_DISABLE_MASTER +) + +# Sign the transaction +tx_disable_master_key_signed = safe_sign_and_autofill_transaction(tx_disable_master_key, wallet=test_wallet, client=client) +submit_tx_disable = send_reliable_submission(client=client, transaction=tx_disable_master_key_signed) +submit_tx_disable = submit_tx_disable.result +print(f"\n Submitted a DisableMasterKey tx. Result: {submit_tx_disable['meta']['TransactionResult']}") +print(f" Tx content: {submit_tx_disable}") + +# Verify Account Settings +get_acc_flag = AccountInfo( + account=myAddr +) +response = client.request(get_acc_flag) + +if response.result['account_data']['Flags'] & asfDisableMaster: + print(f"\nAccount {myAddr}'s master key has been disabled, account is blackholed.") + +else: + print(f"\nAccount {myAddr}'s master key is still enabled, account is NOT blackholed")