Miyagi_newbie Posted November 29, 2019 Share Posted November 29, 2019 I am following this very nice set of instructions to send XRP in testate. https://xrpl.org/send-xrp.html however, after I generate the test key and secret , Here is the steps I use: cat send_xrp.js: async function doSubmit(txBlob) { const latestLedgerVersion = await api.getLedgerVersion() const result = await api.submit(txBlob) console.log("Tentative result code:", result.resultCode) console.log("Tentative result message:", result.resultMessage) // Return the earliest ledger index this transaction could appear in // as a result of this submission, which is the first one after the // validated ledger at time of submission. return latestLedgerVersion + 1 } const earliestLedgerVersion = doSubmit(txBlob) api.on('ledger', ledger => { console.log("Ledger version", ledger.ledgerVersion, "was just validated.") if (ledger.ledgerVersion > maxLedgerVersion) { console.log("If the transaction hasn't succeeded by now, it's expired") } }) // Continues from previous examples. // earliestLedgerVersion was noted when the transaction was submitted. // txID was noted when the transaction was signed. try { tx = await api.getTransaction(txID, {minLedgerVersion: earliestLedgerVersion}) console.log("Transaction result:", tx.outcome.result) console.log("Balance changes:", JSON.stringify(tx.outcome.balanceChanges)) } catch(error) { console.log("Couldn't get transaction outcome:", error) } and when I run it. I keep getting : node send_xrp.js /home/ec2-user/project/sendtext.js:67 tx = await api.getTransaction(txID, {minLedgerVersion: earliestLedgerVersion}) ^^^^^ SyntaxError: await is only valid in async function at Module._compile (internal/modules/cjs/loader.js:723:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) ---------cut here---------------------- Can some one here point out when I did wrong and so I can get a success return code? Thank you. Link to comment Share on other sites More sharing options...
ZIGXRP Posted November 29, 2019 Share Posted November 29, 2019 Might be running an old version of Node perhaps? I believe await calls are supported on more recent versions. Link to comment Share on other sites More sharing options...
Miyagi_newbie Posted December 7, 2019 Author Share Posted December 7, 2019 Thank you, ZIGXRP. I am running node 12.13.1: $ node --version v12.13.1 $ node send.js /home/ubuntu/my_ripple_experiment/sendtext.js:67 tx = await api.getTransaction(txID, {minLedgerVersion: earliestLedgerVersion}) ^^^^^ SyntaxError: await is only valid in async function at Module._compile (internal/modules/cjs/loader.js:895:18) at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10) at Module.load (internal/modules/cjs/loader.js:815:32) at Function.Module._load (internal/modules/cjs/loader.js:727:14) at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) at internal/main/run_main_module.js:17:11 Link to comment Share on other sites More sharing options...
Dario_o Posted December 7, 2019 Share Posted December 7, 2019 9 hours ago, Miyagi_newbie said: tx = await api.getTransaction(txID, {minLedgerVersion: earliestLedgerVersion}) i read on the tutorial page> The RippleAPI getTransaction() method only returns success if the transaction is in a validated ledger version. Otherwise, the await expression raises an exception. Link to comment Share on other sites More sharing options...
Dario_o Posted December 7, 2019 Share Posted December 7, 2019 1 minute ago, Dario_o said: validated ledger version you can read more about at "1. Get Transaction Status" here https://xrpl.org/look-up-transaction-results.html Link to comment Share on other sites More sharing options...
jn_r Posted December 7, 2019 Share Posted December 7, 2019 On 11/29/2019 at 4:46 PM, Miyagi_newbie said: Can some one here point out when I did wrong and so I can get a success return code? It is purely nodejs/javascript error (not ripple-lib related). When you use an 'await' you are only allowed to do that in an 'async' function. Which is logical, javascript wants to be strict here for a change: You can only (a)wait for a function to end or succeed if the overlying function itself is designed as asynchronous. And that implies that also that function must be awaited by for proper results and be wrapped in an async function by itself, etc.etc. What you can do is wrap the try/catch block in a asynchronous main function and then call this function. like this: async function main() { try { tx = await api.getTransaction(txID, {minLedgerVersion: earliestLedgerVersion}) console.log("Transaction result:", tx.outcome.result) console.log("Balance changes:", JSON.stringify(tx.outcome.balanceChanges)) } catch(error) { console.log("Couldn't get transaction outcome:", error) } } main() // no need for await here, just call the async function I don't think your script will work after this, but at least will help you through this first error ;-) Happy coding Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now