I am a PHP developer, and today I’m going to tell you about the steps and the issues I faced while creating the Dogecoin Crypto Wallet (hereinafter DOGE). Technically, it is necessary to develop a website where users can create wallets for themselves, receive, store, and send DOGE.
The simplest and most relevant solution, as it seems, is to buy a dedicated server, run Dogecoin nodes (node) on it, and connect to it locally via RPC. But this option initially did not work out for 2 reasons.
Firstly, due to the cost of the server, a server with the necessary parameters costs about $50 per month. This project was not originally intended to be commercial. It was designed to be free for users, so the cost of its maintenance should be minimal.
Secondly, node support requires a qualified specialist in this field, and this is also an additional cost. We tried using our own resources to raise the Dogecoin node, but it was extremely unstable – it often hung up or appeared out of sync with the main network, and this, of course, frustrated us.
To work with a foreign node there are three questions have to be answered:
1) How to create addresses and where to store keys?
2) How to receive new transactions?
3) How to generate new transactions?
The first question was not so simple. After reading tons of articles and checking megabytes of codes (not only in PHP), a set of libraries was compiled that made it possible to generate a key pair and an address.
The second question was the simplest. To find out which transaction is confirmed, you need to look at the new blocks. How to receive new blocks? Using the “slowness” of the blockchain, you can interrogate a node with some periodicity (even once a minute). And if a new block appears, request its contents from the node. Even if the transaction is received 2 minutes later, no one will complain, and given the need for several confirmations, this will be generally imperceptible.
The solution to the third question required a huge amount of time and effort. There was no ready-made solution. Transaction formation is described many times, but without examples. And those examples that existed- contained only the simplest options. It’s good that Dogecoin is built on the principle of Bitcoin. Most of the information was obtained from there, as it turned out, the formation of an optimal transaction is a complex process. To get a low commission, the transaction length should be as short as possible, so, we need an algorithm that selects from a dozen outputs those that will give the minimum “change”, and this change cannot be less than dust! Debugging and testing this algorithm took several months.
Now back to the issue of connecting to the blockchain.
The first implementation option is node rental. The search returned several options, but all of them are either non-Dogecoin or costing several hundred dollars a month.
The second option is to connect via the API block explorer. A search on the “Dogecoin blockexplorer API” returned the following options:
https://www.sochain.com/DOGE: and https://chain.so/DOGE/: – this is the same resource from Block.io, Inc., there is an API https://sochain.com/api but it works only from the browser! Site protection does not miss calls from the script.
https://blockchair.com/dogecoin: is a powerful resource. Cons – the difficulty of getting an API key for free and the high cost of a paid one.
https://doge.tokenview.com/: 500 Internal Server Error
https://cryptoapis.io/: Limit of 500 calls per day
https://live.blockcypher.com/doge/ – a great resource! Original transaction signing technique. Cons: limits on the number of API calls per minute, node desync (transactions sent through them are not visible to other nodes). The initial study we did here.
https://dogeblocks.com/: Insight was originally here with its API – a great free resource! We used it for a long time. But then it “died” and did not work for several months. And now there is a Blockbook that can’t give UTXO to several addresses at once.
https://dogechain.info/: – also a resource from Block.io, Inc. Free, but limited API https://dogechain.info/api/blockchain_api: there is no “get block transactions” and there is no “get UTXO at multiple addresses”. For a while, it was the only resource on the network through which we could “communicate” with Dogecoin. To get the block transactions, I even had to parse the HTML page.
Everything was unstable, and so, once, one of the users advised the resource http://nownodes.io/ This resource provides rental nodes. Most of them have the Blockbook API installed. We contacted representatives and were given a key. Since then we have been working with them.GET API KEY
In a nutshell:
To create a web wallet, the following APIs are minimally required:
1) Get the last (maximum) block number in the network
2) Get the content/data (not only txid) of all transactions of the block
3) Get a balance of one address and several addresses (not available in Blockbook)
4) Get a UTXO list of one address and several addresses (not available in Blockbook)
5) Send the generated and signed transaction to the network
P.S. As it turned out, just sending a transaction to the network is not enough! Even if the node returned a positive response (no error), this does NOT mean that the transaction has entered mempool. Some time after sending it is necessary to check “does the transaction exist?” Sometimes it just disappears! We still do not understand the reason behind this.GET API KEY