mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2026-04-29 15:37:48 +00:00
Rewrite 'Assign a Regular Key Pair' tutorial w/ JS code sample Add Python sample code for assign regular key Slight rephrasings re: changing regular key Remove emoji from code sample per @maria-robobug review Co-authored-by: Maria Shodunke <maria-robobug@users.noreply.github.com> More changes per review Co-authored-by: Maria Shodunke <maria-robobug@users.noreply.github.com> Add new code samples for setting up multisigning Rewrite 'Set Up Multi-signing' Tutorial Remove emoji from multi-signing setup code sample Apply suggestions from review Co-authored-by: Maria Shodunke <maria-robobug@users.noreply.github.com> Adjust 'See Also' in multi-signing setup New code samples for sending multi-signed tx Rewrite 'Send a Multi-Signed Transaction' tutorial Remove old multisigning code samples These code samples weren't bad, but they didn't fully embody best practices like reliable transaction submission, and they're fully obsolete with the new multi-signing code samples in place. Apply suggestions from review Co-authored-by: Maria Shodunke <maria-robobug@users.noreply.github.com> Rewrite 'Remove a Regular Key Pair' tutorial Remove emojis from code sample Remove regular key: edits per review Rewrite "Disable Master Key Pair" tutorial Remove emojis from code samples Disable master key pair: edits per @maria-robobug review Co-authored-by: Maria Shodunke <maria-robobug@users.noreply.github.com>
78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
import xrpl from 'xrpl'
|
|
|
|
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
|
await client.connect()
|
|
|
|
console.log('Funding new wallet from faucet...')
|
|
const { wallet } = await client.fundWallet()
|
|
console.log(`Funded. Master key pair:
|
|
Address: ${wallet.address}
|
|
Seed: ${wallet.seed}
|
|
`)
|
|
|
|
// Generate a new key pair to use as the regular key ---------------------------
|
|
const algorithm = 'ed25519'
|
|
const regularKeyPair = xrpl.Wallet.generate(algorithm)
|
|
console.log(`Generated regular key pair:
|
|
Address: ${regularKeyPair.address}
|
|
Seed: ${regularKeyPair.seed}
|
|
Algorithm: ${algorithm}
|
|
`)
|
|
|
|
// Send SetRegularKey transaction ----------------------------------------------
|
|
const regularKeyTx = {
|
|
TransactionType: 'SetRegularKey',
|
|
Account: wallet.address,
|
|
RegularKey: regularKeyPair.address
|
|
}
|
|
xrpl.validate(regularKeyTx)
|
|
|
|
console.log('Signing and submitting the SetRegularKey transaction:',
|
|
JSON.stringify(regularKeyTx, null, 2))
|
|
const response = await client.submitAndWait(regularKeyTx, { wallet, autofill: true })
|
|
|
|
// Check result of the SetRegularKey transaction -------------------------------
|
|
console.log(JSON.stringify(response.result, null, 2))
|
|
const setRegularKeyResultCode = response.result.meta.TransactionResult
|
|
if (setRegularKeyResultCode === 'tesSUCCESS') {
|
|
console.log('Regular Key set successfully.')
|
|
} else {
|
|
console.error(`SetRegularKey failed with code ${setRegularKeyResultCode}.`)
|
|
client.disconnect()
|
|
process.exit(1)
|
|
}
|
|
|
|
// Send a test transaction using the regular key -------------------------------
|
|
const testTx = {
|
|
TransactionType: 'AccountSet',
|
|
Account: wallet.address
|
|
}
|
|
xrpl.validate(testTx)
|
|
|
|
console.log('Signing and submitting the test transaction using the regular key')
|
|
const testResponse = await client.submitAndWait(testTx, {
|
|
wallet: regularKeyPair, // IMPORTANT: use the regular key pair here
|
|
autofill: true
|
|
})
|
|
|
|
// Check result of the test transaction ----------------------------------------
|
|
console.log(JSON.stringify(testResponse.result, null, 2))
|
|
const testResultCode = testResponse.result.meta.TransactionResult
|
|
const testSigningPubKey = testResponse.result.tx_json.SigningPubKey
|
|
if (testResultCode === 'tesSUCCESS') {
|
|
console.log('Test transaction was successful.')
|
|
} else {
|
|
console.log(`Test transaction failed with code ${testResultCode}`)
|
|
}
|
|
if (testSigningPubKey === regularKeyPair.publicKey) {
|
|
console.log('This transaction was signed with the regular key pair.')
|
|
} else if (testSigningPubKey === wallet.publicKey) {
|
|
console.warn('This transaction was signed with the master key pair.')
|
|
} else {
|
|
console.warn(`Unexpected signing key mismatch.
|
|
Regular key: ${regularKeyPair.publicKey}
|
|
Key used: ${testSigningPubKey}`)
|
|
}
|
|
|
|
client.disconnect()
|