This is my xrpl function. It comes from the xrpl tutorial and should work. But it returns tefBAD_AUTH error.
I am writing the xrpl dapps and it is kind of web3.
const xrpl = require("xrpl");
const poolSecret = "sEd**********************";
const poolWallet = xrpl.Wallet.fromSeed(poolSecret)
async function main(addr) {
console.log("Connecting to Testnet...")
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
await client.connect()
// Prepare transaction -------------------------------------------------------
const prepared = await client.autofill({
"TransactionType": "Payment",
"Account": addr,
"Amount": xrpl.xrpToDrops("1"),
"Destination": poolWallet.address
})
const max_ledger = prepared.LastLedgerSequence
console.log("Prepared transaction instructions:", prepared)
console.log("Transaction cost:", xrpl.dropsToXrp(prepared.Fee), "XRP")
console.log("Transaction expires after ledger:", max_ledger)
// Sign prepared instructions ------------------------------------------------
const signed = poolWallet.sign(prepared)
console.log("Identifying hash:", signed.hash)
console.log("Signed blob:", signed.tx_blob)
// Submit signed blob --------------------------------------------------------
try {
const tx = await client.submitAndWait(signed.tx_blob)
// Wait for validation -------------------------------------------------------
// submitAndWait() handles this automatically, but it can take 4-7s.
// Check transaction results -------------------------------------------------
console.log("Transaction result:", tx.result.meta.TransactionResult)
console.log("Balance changes:", JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2))
// End of main()
client.disconnect()
} catch (e) {
console.log(e)
}
}
main("rf*******************************");
But it returns this error. This is the full logs.
Connecting to Testnet...
Prepared transaction instructions: {
TransactionType: 'Payment',
Account: 'rf*******************************',
Amount: '1000000',
Destination: 'ra*******************************',
Flags: 0,
Sequence: 36726053,
Fee: '12',
LastLedgerSequence: 36750914
}
Transaction cost: 0.000012 XRP
Transaction expires after ledger: 36750914
Identifying hash: 79D3030E5C7F53B04C7FD9C4BC0D7D65BEEEAFA2787BB72C87CA8F6B553BA32B
Signed blob: 12000022000000002402306525201B0230C6426140000000000F424068400000000000000C7321EDA47EA21FCF73BF28D57230BCECB075B2A710C0A15E1D49DA2CA30AE672D667067440B5B294834715D70A90DEFECCD66C7AF839FEE250ED078249C2D85315F66D562856025B2812F1285065D4BABC638DC6488F604C4381D9EFF91E6C8795E09E810581144A0CD16399904DE78F0B132D8CC7105091BB911A83143FF554299C3A982782E1201E87E73B0284D73F79
**XrplError: The latest ledger sequence 36750915 is greater than the transaction's LastLedgerSequence (36750914).**
Preliminary result: tefBAD_AUTH
at /home/barnyjake/work/xrp/node_modules/xrpl/dist/npm/sugar/submit.js:65:19
at Generator.next (<anonymous>)
at fulfilled (/home/barnyjake/work/xrp/node_modules/xrpl/dist/npm/sugar/submit.js:5:58) {
data: undefined
}
The address that I use works fine in the wallet.
I am using ubuntu 20.04 and I tried this with node v14 & v16.
Two things to try:
From the "bad auth" message Change the client you are trying to connect to, try "wss://testnet.xrpl-labs.com/" which explicitly has CORS support (https://xrpl.org/public-servers.html)
From the "latest ledger sequence..." message Short answer: try changing, (or explicitly setting) your Flags value to 2147483648.
Long answer: I had the same error for an "NFTokenCreateOffer" transaction type. It corrected for me when I set the "Flags" property of my transaction to a correct value.
From your output, it looks like your Flags is set to 0 which I don't think matches any true flag for the payment transaction type.
I have a my own system that I have coded that utilizes the "payment" transaction, in which I set Flags to "2147483648" (tfFullyCanonicalSig - https://xrpl.org/transaction-common-fields.html#flags-field), which I know says is deprecated, but it works for me.
My payment transaction looks like this prior to autofill being called:
I hope this helps