Calling DeSo node using backend api
DeSo node exposes a set of APIs for clients to call to inquire about the information from the underlying blockchain. Wide varieties of these APIs use the public key portion of an account. That means, if you have access a public key, which can be anybody's public key, you can call the API. If you are interested, https://docs.deso.org/devs/backend-api explains the meaning of each API call in more detail. I have to admit that the documentation can use some love from DeSo team.
Now, let's dive into how to make the api call. Make sure you have 'curl' installed in your system. Since https://node.deso.org node does not currently require an api key, we will use this node for the guide:
When you have to specify the request JSON body, make sure the properties and the values are wrapped between \"\". For example:
-d "{\"PublicKeyBase58Check\":\"\"}"
Otherwise, you will get a JSON parsing error.
Now, let's look at the actual API calls:
- Health check
> curl -G https://node.deso.org/api/v0/health-check
200
This should return '200'. In that case, the node is healthy and running. The status code is something other than '200', then either access to the node has been blocked or it is down some reason.
- Get exchange rates:
> curl -G https://node.deso.org/api/v0/get-exchange-rate
{"SatoshisPerDeSoExchangeRate":165480,"USDCentsPerBitcoinExchangeRate":5741120,"NanosPerETHExchangeRate":47168421052,"USDCentsPerETHExchangeRate":448100,"NanosSold":8532253885390055,"USDCentsPerDeSoExchangeRate":9500,"USDCentsPerDeSoReserveExchangeRate":7500,"BuyDeSoFeeBasisPoints":10,"SatoshisPerBitCloutExchangeRate":165480,"USDCentsPerBitCloutExchangeRate":9500,"USDCentsPerBitCloutReserveExchangeRate":7500}
- Get app state:
> curl -X POST -H "Content-Type: application/json" -d "{\"PublicKeyBase58Check\": \"\"}" https://node.deso.org/api/v0/get-app-state
{"MinSatoshisBurnedForProfileCreation":100000,"BlockHeight":82345,"IsTestnet":false,"HasStarterDeSoSeed":true,"HasTwilioAPIKey":true,"CreateProfileFeeNanos":1000000,"CompProfileCreation":true,"DiamondLevelMap":{"1":50000,"2":500000,"3":5000000,"4":50000000,"5":500000000,"6":5000000000,"7":50000000000,"8":500000000000},"HasWyreIntegration":true,"HasJumioIntegration":true,"BuyWithETH":true,"USDCentsPerDeSoExchangeRate":9500,"JumioDeSoNanos":41666666,"TransactionFeeMap":{"ACCEPT_NFT_BID":null,"ACCEPT_NFT_TRANSFER":null,"AUTHORIZE_DERIVED_KEY":null,"BASIC_TRANSFER":null,"BITCOIN_EXCHANGE":null,"BLOCK_REWARD":null,"BURN_NFT":null,"CREATE_NFT":null,"CREATOR_COIN":null,"CREATOR_COIN_TRANSFER":null,"FOLLOW":null,"LIKE":null,"NFT_BID":null,"NFT_TRANSFER":null,"PRIVATE_MESSAGE":null,"SUBMIT_POST":null,"SWAP_IDENTITY":null,"UNSET":null,"UPDATE_BITCOIN_USD_EXCHANGE_RATE":null,"UPDATE_GLOBAL_PARAMS":null,"UPDATE_NFT":null,"UPDATE_PROFILE":null},"BuyETHAddress":"0xeF9865D228e72B3a32ACc8064Ed9eDBCC3E82E60","Nodes":{"1":{"Name":"DeSo","URL":"https://node.deso.org","Owner":"diamondhands"},"10":{"Name":"GiftClout","URL":"https://members.giftclout.com","Owner":"RajLahoti"},"11":{"Name":"DeSocialWorld","URL":"https://desocialworld.com","Owner":"edokoevoet"},"12":{"Name":"NFTz","URL":"https://nftz.zone","Owner":"mvanhalen"},"2":{"Name":"BitClout","URL":"https://bitclout.com","Owner":"diamondhands"},"3":{"Name":"Diamond","URL":"https://diamondapp.com","Owner":"Zordon"},"4":{"Name":"CloutFeed","URL":"https://apps.apple.com/app/id1561532815","Owner":"Ribal"},"5":{"Name":"Flick","URL":"https://flickapp.com","Owner":"nigeleccles"},"6":{"Name":"tijn's club","URL":"https://tijn.club","Owner":"tijn"},"7":{"Name":"Nacho Average","URL":"https://nachoaverage.com/","Owner":"ClayPerryMusic"},"8":{"Name":"love4src","URL":"https://love4src.com","Owner":"kanshi"},"9":{"Name":"Supernovas","URL":"https://supernovas.app","Owner":"fransarthur"}},"USDCentsPerBitCloutExchangeRate":9500,"JumioBitCloutNanos":41666666}
The information contains a list of public nodes. I haven't tried to access those nodes, but if you would like you will probably want to call into those nodes to get information about those nodes as well. It also contains information about the cost of profile creation in the node among other things.
4 Get user profile
> curl -X POST -H "Content-Type: application/json" -d "{\"PublicKeyBase58Check\": \"BC1YLiUw63zayemTq5c714G1Fuo6iTsuBbYwnLpm9uXr5KcA9688fmw\", \"NumToFetch\": 1}" https://node.deso.org/api/v0/get-profiles
{"ProfilesFound":[{"PublicKeyBase58Check": "BC1YLiUw63zayemTq5c714G1Fuo6iTsuBbYwnLpm9uXr5KcA9688fmw", "Username": "zknerd","Description": "@DeSoShell","IsHidden": false,"IsReserved": false,"IsVerified": false,"Comments": null,"Posts":[...],"CoinEntry":{"CreatorBasisPoints": 1500,"DeSoLockedNanos": 2127252462,"NumberOfHolders": 1,"CoinsInCirculationNanos": 12860945970,"CoinWatermarkNanos": 19525283191,"BitCloutLockedNanos": 2127252462},"CoinPriceDeSoNanos": 496212179,"CoinPriceBitCloutNanos": 496212179,"UsersThatHODL": [],"IsFeaturedTutorialWellKnownCreator": false,"IsFeaturedTutorialUpAndComingCreator": false}],"NextPublicKey": null}
I removed all the posts so that you will get an idea of the type of information you can extract from using the API. The posts also have some interesting information but that will be for some other day.
I hope you get an idea how to call the API directly and the kind of things you can do using the raw API. Finally, if there are no open nodes, you can run your own node and call into it. DeSo documenation on how to run a node (https://docs.deso.org/devs/running-a-node) will give you an idea on how do that.