XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 510 forks source link

ValidationError: instance.id does not match pattern ripple #1343

Closed devgreek closed 3 years ago

devgreek commented 3 years ago

I'm setting up a function that calls and receives any payments made then I run into this error as I begin

const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
});
api.on('error', (errorCode, errorMessage) => {
  console.log(errorCode + ': ' + errorMessage);
});
api.on('connected', () => {
  console.log('connected');
});
api.on('disconnected', (code) => {
  console.log('disconnected, code:', code);
});
api.connect().then(() => {
  /* insert code here */

    let checks = 0
    let checktx = setInterval(() => {
        if (checks < 900 ){
            api.getLedgerVersion().then((ledger) => {
                api.getTransaction(addr, {minLedgerVersion:ledger}).then((txs) => {
                    console.log(txs)
                })
            })
            checks++
        } else {
            clearInterval(checktx)
            console.log('Payment is cancelled')
            io.emit({msg: 'Payment is cancelled'})
        }
    }, 1000)

}).then(() => {
  return api.disconnect();
}).catch(console.error);
elmurci commented 3 years ago

what is the value of addr?

devgreek commented 3 years ago

I fixed it, silly mistake, it's getTransactions() not getTransaction()

The code emit real-time payments on your address

In case anyone need this, now I have to find the same solution for ethereum

devgreek commented 3 years ago
const app = express()
const http = require('http').Server(app)
const io = require('socket.io')(http)
const addr = 'rppm2hDuKZVhN1GZ8E3E9syuaTFne53cL6'
const server = 'wss://s.altnet.rippletest.net:51233'

const RippleAPI = require('ripple-lib').RippleAPI
const api = new RippleAPI({server:server})

api.on('error', (code, msg) => {
    console.log(code, msg)
})

api.on('connected', ()=> {
    console.log('connected to testnet');
})

api.on('disconnected', (code)=> {
    console.log('disconnected to testnet');
})

api.connect().then((result) => {

    let checks = 0
    let checktx = setInterval(() => {
        if (checks < 900 ){
            api.getLedgerVersion().then((ledger) => {
                api.getTransactions(addr, {minLedgerVersion:ledger}).then((txs) => {
                    console.log(txs)
                    for (tx of txs) {
                        if(tx.specification.destination.tag === 41){
                            clearInterval(checktx)
                            io.emit('emit', {
                                id: elem.id,
                                from: elem.specification.destination.source.address,
                                tag:  elem.specification.destination.source.tag,
                                amount: elem.specification.destination.amount.value,
                                msg: 'payment was recievd'
                            })
                        }
                    }
                })
            })
            checks++
        } else {
            clearInterval(checktx)
            console.log('Payment is cancelled')
            io.emit({msg: 'Payment is cancelled'})
        }
    }, 1000)

}).catch((err) => {
    console.log(err);    
});
elmurci commented 3 years ago

Are you happy to close this issue @Yeppman?

devgreek commented 3 years ago

Are you happy to close this issue @Yeppman?

yes