Last active
March 13, 2021 03:19
-
-
Save mDuo13/4c3d5bfe7581591c159f024032c11bf9 to your computer and use it in GitHub Desktop.
initial-seq-glitch.html
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
<!DOCTYPE html> | |
<html><head><meta charset="utf-8" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous"></script> | |
<script src="https://unpkg.com/ripple-lib@1.9.1/build/ripple-latest-min.js"></script> | |
<script type="application/javascript"> | |
async function main() { | |
// Connect ------------------------------------------------------------------- | |
api = new ripple.RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'}) | |
await api.connect() | |
// Get Testnet creds | |
const response = await fetch("https://faucet.altnet.rippletest.net/accounts", { | |
method: 'POST', | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
body: "{}" | |
}) | |
const data = await response.json() | |
const address = data.account.address | |
const secret = data.account.secret | |
// First account_info. This is the weird one. -------------------------------- | |
console.log(await api.request("account_info", {account: address})) | |
// Workaround, commented out. Wait until the account is in a validated ledger. | |
// console.log("Waiting until we have a validated starting sequence number...") | |
// If you go too soon, the funding transaction might slip back a ledger and | |
// then your starting Sequence number will be +1. | |
// while (true) { | |
// try { | |
// await api.request("account_info", {account: address, ledger_index: "validated"}) | |
// break | |
// } catch(e) {} | |
// } | |
// Send AccountSet transaction ----------------------------------------------- | |
const prepared = await api.prepareTransaction({ | |
"TransactionType": "AccountSet", | |
"Account": address | |
}) | |
console.log("Prepared transaction:", prepared.txJSON) | |
const signed = api.sign(prepared.txJSON, secret) | |
const prelim_result = await api.request("submit", {"tx_blob": signed.signedTransaction}) | |
console.log("Preliminary result:", prelim_result) | |
console.log("Waiting 15 seconds to check...") | |
// Stuff to do 15 seconds later: | |
fifteen_later = async function() { | |
// Get Account Info -------------------------------------------------------- | |
let account_info = await api.request("account_info", { | |
"account": address, | |
"ledger_index": "validated" | |
}) | |
// The transaction probably still isn't validated and it probably never will be. | |
console.log(await api.request("tx", {transaction: signed.id})) | |
} | |
setTimeout(fifteen_later, 15000) | |
} | |
main() | |
</script> | |
</head><body>Open your browser's console (F12) to see the logs.</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment