Jump to content

Public access to API or WebSocket


 Share

Recommended Posts

Hi,

I put togheter a couple of projects on GitHub and finally I have my code in F# and I can use on my .Net website.
XRPL.org is where I look for the documentation. I use the WebSockets instead of the API because (by memory) the API does not expose something that I needed. 
Anyway, I can now Set Domain and MessageKey on the Account. Get a Transaction. Get Account transactions. Create a new Address (not yet the X address) and also Create,Sign(offline) and Submit a Payment transaction.

I'm always using the wss://s1.ripple.com endpoint but, if I remember correctly, this is discouraged.
I know that the best way is to run your own rippled server. I will not be able to do that for a while.

Now, without a owned server I cannot have access to the XRP Ledger "offcially"?  
1. I know that some "admin" functionalities are only available from the server itself (or in some way not public) but all the other methods are by default exposed by the node/validator o not?
2. If the API are the official entrypoint the WebSocket is "optional" ?
3. I picked up some URL from here (https://livenet.xrpl.org/network/validators)  like validator.ripple.com or bithomp.com but they don't work. 

First thing, I'll start to look for what is the difference between node and validator but some clarification about public API/WebSocket will be really appreciated,

Edited by AlessandroPiccione
Link to comment
Share on other sites

Why F# :P

Would prefer C# or even better JavaScript/NodeJS or perhaps some wrapped version with TypeScript

You don't need to run your own rippled server per se, although its encouraged to do so since public servers from Ripple might become unavailable at any time. And yes, some API's - Admin methods - are only available when using a local rippled server. If understand correctly public methods should always be available.

WebSockets allow you to setup a connection whereas both the client and server can send messages to each other with the same connection, which is kept open. So the client might for example monitor incoming payments from the server (or whatever event) and run some logic based on that event.

The "API" technique is simple when the client send some JSON calls to the rippled server and gets a response. There is no connection that remains open.

You call different endpoints depending if you are using JSON calls or WebSocket since they are different protocols (HTTS vs WSS) - but they lead to the same ledger.

Everything is detailed on https://xrpl.org/get-started.html

EDIT:  Just to clarify - there is no "best" method per se. It depends on what you are trying to get done.

Edited by JustKevStockholm
Link to comment
Share on other sites

You can use the wws://s1.ripple.com

You won't get the same server each connection, but it'll be a ripple controlled validator.

If you want to save yourself a lot of time and headache you could call c# from f# and use the library I created

https://github.com/jargoman/RippleLibSharp

You really don't want to be writing everything from scratch. If you can find an F# library, use that. If not you can import a dll written in any language that the .net environment supports. 

I prefer the library I wrote but that's because it's object oriented which might not be the best solution for F# which I read is functional



I whipped up an example quick. Not sure how accurate it is. 

open rippleLibSharp
// not sure how you'd import each namespace

let servers = ["r1.ripple.com"] // it's an array so as many as you want. If connection to one fails it will try the next

var ci = ConnectionSettings()
ci.ServerUrls = servers;
ci.Reconnect = true;

var ni = NetworkInterface(ci)


var payment = RipplePaymentTransaction()
payment.amount = 100 // drops
payment.currency = "XRP"
payment.destination = someaddress
payment.account = anotheraddress

var signed = payment.signRippleDotNet(key) // sign with ripples official c# code
var task = payment.submit(ni)
task.wait()

var response = task.result

if response.hasError then 
response.error 
response.error_code 
response.error_message 

else

response.status // rippled response string



You said you signed a message already using f# so maybe you already have a library to use. 

Link to comment
Share on other sites

Just now, jargoman said:

You can use the wws://s1.ripple.com

You won't get the same server each connection, but it'll be a ripple controlled validator.

If you want to save yourself a lot of time and headache you could call c# from f# and use the library I created

https://github.com/jargoman/RippleLibSharp

You really don't want to be writing everything from scratch. If you can find an F# library, use that. If not you can import a dll written in any language that the .net environment supports. 

I prefer the library I wrote but that's because it's object oriented which might not be the best solution for F# which I read is functional



I whipped up an example quick. Not sure how accurate it is. 


open rippleLibSharp
// not sure how you'd import each namespace

let servers = ["r1.ripple.com"] // it's an array so as many as you want. If connection to one fails it will try the next

var ci = ConnectionSettings()
ci.ServerUrls = servers;
ci.Reconnect = true;

var ni = NetworkInterface(ci)


var payment = RipplePaymentTransaction()
payment.amount = 100 // drops
payment.currency = "XRP"
payment.destination = someaddress
payment.account = anotheraddress

var signed = payment.signRippleDotNet(key) // sign with ripples official c# code
var task = payment.submit(ni)
task.wait()

var response = task.result

if response.hasError then 
response.error 
response.error_code 
response.error_message 

else

response.status // rippled response string



You said you signed a message already using f# so maybe you already have a library to use. 



Edit: the fact I created some f# code in 5 minutes without ever using the language is cool. It's a decent language. 

Link to comment
Share on other sites

19 minutes ago, jargoman said:

Edit: the fact I created some f# code in 5 minutes without ever using the language is cool. It's a decent language. 

To be honest I haven't really cared about the functional programming paradigm, so I have ignored all that altogether including F# :P

Link to comment
Share on other sites

There’s no “official” access. You can run your own server if you want, or you can use a server offered by someone else.

You should look into xrpl.ws which provides WSS access. It has servers all over the world, implements seamless failover between them and more; it provides—in my mind at least—much better quality of service than s1.ripple.com.

And, as a bonus, it’s entirely independent of Ripple.:clapping:

Link to comment
Share on other sites

Posted (edited)

Thanks to all,

https://xrpl.org/get-started-with-the-rippled-api.html#public-servers
I'm using wss://s1.ripple.com/ and wss://s2.ripple.com/

Quote

You won't get the same server each connection, but it'll be a ripple controlled validator.

Where did you get they are behind a route balancer?

About F#. I'm a C# developer since ... when it was created. I use JavaScript since... before that. TypeScript is also in my skills
I'm studing F#, and I think is better (still mix both in my projects). I don't suggest an approach C# -> F# but maybe to really understand Functional Programming and it's benefits.

 

Quote

There’s no “official” access

This is actually the answer to my question. I'll add xrpl.ws to the S1 ans S2 to have at least 3 URLs.

So, to have it completely clear, when you run rippled you can set it up to expose API and WebSockets (are they part of rippled or not?) or disable them, or also make it private or accessible only to an IP withelist? Whay is correct of this?
A rippled is a node of the ripplenet but exposing  functionalities outside is not "mandatory" (apart from the other nodes) ? Or any of the validatords in the UNL list has the public API exposed (on a different port) ?

Edited by AlessandroPiccione
Link to comment
Share on other sites

1 hour ago, AlessandroPiccione said:

So, to have it completely clear, when you run rippled you can set it up to expose API and WebSockets (are they part of rippled or not?) or disable them, or also make it private or accessible only to an IP withelist? Whay is correct of this?

Correct. And they are already part of rippled.

1 hour ago, AlessandroPiccione said:

A rippled is a node of the ripplenet but exposing  functionalities outside is not "mandatory" (apart from the other nodes) ? Or any of the validatords in the UNL list has the public API exposed (on a different port) ?

A rippled is a node of XRPL (XRP ledger). Ripplenet (but it comes under an official name I think) is a private network of banks using Interledger-like protocol and custom messages and other software from Ripple and it has nothing to do with XRPL.
I don't think any validator in the UNL is publicly exposing the API.

 

BTW running your own rippled is "very cheap". I run mine on a NUC with good RAM and SSD. Total cost was around 500$ + network + electricity. You'll have a much more reliable node, with lower latency and admin rights. On public servers there are also banwidth limitations.

Link to comment
Share on other sites

I am running primarily on wss://xrpl.ws (which actually is a set of multiple rippled servers). If it fails I jump to wss://s1.ripple.com or next, wss://s2.ripple.com.

This works pretty well for me. Just make sure to catch and handle the errors because network errors and node hick-ups will definitely occur. 

Link to comment
Share on other sites

19 hours ago, JustKevStockholm said:

To be honest I haven't really cared about the functional programming paradigm, so I have ignored all that altogether including F# :P

I decided to earn a university diploma in software development to get the certification of what I already know, they are teaching me lisp based "beginner student language". It's functional. 

If everything is a function you can unit test each function and create well defined, properly structured code that is unit tested. I prefer object oriented programming. C# is probably my favourite language because it's the perfect middle ground between flexibility and power while still being high level. If it wasn't for ide's with autocomplete, debugging, code refactoring ect, I'd probably prefer javascript. Javascript is one of those languages that seems confusing until you're comfortable with it. Then it's incredibly easy. 

Link to comment
Share on other sites

6 hours ago, AlessandroPiccione said:

Where did you get they are behind a route balancer?

Thank you for the correct terminology. 

If you disconnect and reconnect. The server info command will return different server information. 

Link to comment
Share on other sites

1 hour ago, jargoman said:

Javascript is one of those languages that seems confusing until you're comfortable with it.

Perfect description :D.

I'm more like a C++ (but also C#) guy and when I first started to use Javascript I said "what the hell is this?". Then you get used to it and it might be a nice language.

Link to comment
Share on other sites

24 minutes ago, tulo said:

Perfect description :D.

I'm more like a C++ (but also C#) guy and when I first started to use Javascript I said "what the hell is this?". Then you get used to it and it might be a nice language.

same with c++ you're like what the hell is this? Except it never gets easier just more and more complicated lol

Link to comment
Share on other sites

19 hours ago, tulo said:

Perfect description :D.

I'm more like a C++ (but also C#) guy and when I first started to use Javascript I said "what the hell is this?". Then you get used to it and it might be a nice language.

This is why we hate or love JavaScript! :D

EDIT: The trick of understanding this is to acknowledge how JavaScript coerce stuff and how "loose" equality == and "strict" equality ===  comparison works

4n583bhdqnz03mq3t13v.jpg

Edited by JustKevStockholm
Explanation
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.