More messing around with the blockchain: An ATM for SMLY

in blockchain •  last year

Messing around with Litecoin and Smileycoin

Litecoin has adopted all the same features as Bitcoin and the Smileycoin was developed for fun in the first place so let's mess around with the two a little bit. We will work with the raw chains so make sure you are willing to get your hands dirty.

Remember that this is just for fun and at your own risk. Do not send a lot of coins to any address mentioned here.

smiley3-320.jpg

An ordinary ATM is a hole-in-the-wall where you stick your credit card and out comes money. You can also insert money. There are also ATMs where you can select different currencies.

Here is an example of an ATM which gives you SMLY when you insert LTC. We will do this on a Mac. It should also work on a Windows machine and under Linux.

You are going to send LTC to a Litecoin address and get back SMLY to a Smileycoin address. Pretty cool stuff (but this is NOT an atomic swap).

Background

First make sure that you have both a Litecoin wallet and a Smileycoin wallet. Get a Smileycoin address to receive the SMLY coming back. We'll use BL6dZnnFMXZUGXKMZ3fcJm48Gz4DidYKzJ -- but make sure to use your own.

We are going to encode the SMLY address in a Litecoin transaction. A Litecoin transaction normally just moves LTC to a destination address. Some hidden programming magic behind this particular address will read the transaction, figure out how many SMLY correspond to the amount you sent and ship those SMLY back to your SMLY wallet.

This is where you start your Litecoin wallet and open the Console window (see below if you have not done this before). Give the listunspent command and find an unspent transaction output to use as input for your Litecoin transmission. Remember: You do not want to spend a lot of LTC here -- this is completely at your own risk.

Make a note of the amount, the transaction id (TxID) and the vout.

In the transaction example below, the TxID is 42189ba739eef0a75ce4acfdd9249eb86f22d14c44da5b7b439f96c238614801, the vout is 2 and the amount is 0.43240803 LTC.

The unspent amount we are about to use will be split into three parts: (1) The amount actually sent to the destination, (2) Change sent back to our own address and whatever is left over becomes the (3) Transaction fee.

We're going to be careful not to spend too much, since we are just having fun and there really is no guarantee this will work. So let's assume we are going to spend 0.02 LTC to get SMLY and that we need 0.005 LTC for a transaction fee (see below for more on transaction fees). The remainder of the UTXO becomes our change.

The addresses

From above you have a Smileycoin address for receiving the SMLY.

You need a LTC address for receiving the change. Just go into the LTC Console and type getnewaddress to get an address.

For our example we will use LfhYbb6cQBS2Zdh1ieDWmg2Zk42LqBCJF9 as the change address, but of course you will replace this by your own.

Sending data in the blockchain

This is where the fun starts. First take your SMLY address and convert it to hex so that it can be placed as data into the Litecoin transaction. This web page will do that conversion and should look like this when you are done:

Note the innocent looking box labelled optional delimiter string: This box starts off containing a space which you will want to delete.

Copy the output, 424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a for using in a bit.

The structure of the transaction

Our Litecoin transaction will consist of
0.40740803 - the LTC input, vout 2 from TxID 42189ba739eef0a75ce4acfdd9249eb86f22d14c44da5b7b439f96c238614801
0.02 LTC - the LTC amount to be sent to the recipient, LTC address Lcb1iTTGxHacPNK3rdZeyZY5y2wS7Bcn1z
0.38240803 - the LTC change to be sent back to us, LTC address LfhYbb6cQBS2Zdh1ieDWmg2Zk42LqBCJF9
0.005 LTC - the transaction fee
data - the hex coded SMLY address, 424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a

Notice that the sums do add up: 0.40740803=(0.02+0.38240803+0.005)

When you decide to run this example yourself, remember to replace everything by your own amounts and addresses, except for the recipient, LTC address Lcb1iTTGxHacPNK3rdZeyZY5y2wS7Bcn1z which is the address of the LTC-SMLY ATM.

At this stage you have all the addresses, all the amount and the hex representation of the SMLY address. It is time to construct the Litecoin transaction. Go back into Console of the Litecoin wallet and get ready for some fancy stuff.

Creating the transaction

The wallets have a collection of commands which can be used for all sorts of fancy stuff. We will be using the createrawtransaction command. Within the Litecoin wallet this command allows the inclusion of data, which is what we will use to embed the SMLY address. The full command, to be entered in the LTC Command window is:

createrawtransaction '[{"txid":"c7ee53dee8a23e1ab59af4de95648d966ba4dd8072eacee6fb54faf77e48174b","vout":2}]' '{"Lcb1iTTGxHacPNK3rdZeyZY5y2wS7Bcn1z":0.020,"data":"424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a","LgjZJhveCEAitsgVL9v1VtQoUQC4udy6tQ":0.38240803}'

and this will result in a long hex string:
02000000014b17487ef7fa54fbe6ceea7280dda46b968d6495def49ab51a3ea2e8de53eec70200000000ffffffff0380841e00000000001976a914be75c168f39485841c54fc39ad1823427e95a11088ac0000000000000000246a22424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a23824702000000001976a914ebf3f4ee9c3e02467d21845afe3088278f15bb4888ac00000000
Now we are almost ready. This string just needs to be signed by you, the user:

signrawtransaction 02000000014b17487ef7fa54fbe6ceea7280dda46b968d6495def49ab51a3ea2e8de53eec70200000000ffffffff0380841e00000000001976a914be75c168f39485841c54fc39ad1823427e95a11088ac0000000000000000246a22424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a23824702000000001976a914ebf3f4ee9c3e02467d21845afe3088278f15bb4888ac00000000

This returns information with both the signed version of the transaction and an indication of whether the transaction was successfully signed:
{ "hex": "02000000014b17487ef7fa54fbe6ceea7280dda46b968d6495def49ab51a3ea2e8de53eec7020000006a47304402203185aff1d86b8bea7c724602880ad287ae141b6c9f74daad033a4d73315ea51f02206c65d413db0635f1d534bd635452c987e7588e5de634b71e74f3071f054bfaa5012102aa8f3f6c06a41af3fb9d0000ebbba695d373c221b4bf78fd97687e57193cb1b8ffffffff0380841e00000000001976a914be75c168f39485841c54fc39ad1823427e95a11088ac0000000000000000246a22424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a23824702000000001976a914ebf3f4ee9c3e02467d21845afe3088278f15bb4888ac00000000", "complete": true }

This transaction is now ready for sending.

Before sending it, you can change it to a readable form and inspect the elements:
decoderawtransaction 02000000014b17487ef7fa54fbe6ceea7280dda46b968d6495def49ab51a3ea2e8de53eec7020000006a47304402203185aff1d86b8bea7c724602880ad287ae141b6c9f74daad033a4d73315ea51f02206c65d413db0635f1d534bd635452c987e7588e5de634b71e74f3071f054bfaa5012102aa8f3f6c06a41af3fb9d0000ebbba695d373c221b4bf78fd97687e57193cb1b8ffffffff0380841e00000000001976a914be75c168f39485841c54fc39ad1823427e95a11088ac0000000000000000246a22424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a23824702000000001976a914ebf3f4ee9c3e02467d21845afe3088278f15bb4888ac00000000

Within the transaction you will see the SMLY return address hex-coded as an OP_RETURN element:
"asm": "OP_RETURN 424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a"

Now all we need to do is to send the entire, signed, transaction:
sendrawtransaction 02000000014b17487ef7fa54fbe6ceea7280dda46b968d6495def49ab51a3ea2e8de53eec7020000006a47304402203185aff1d86b8bea7c724602880ad287ae141b6c9f74daad033a4d73315ea51f02206c65d413db0635f1d534bd635452c987e7588e5de634b71e74f3071f054bfaa5012102aa8f3f6c06a41af3fb9d0000ebbba695d373c221b4bf78fd97687e57193cb1b8ffffffff0380841e00000000001976a914be75c168f39485841c54fc39ad1823427e95a11088ac0000000000000000246a22424c36645a6e6e464d585a5547584b4d5a3366634a6d3438477a34446964594b7a4a23824702000000001976a914ebf3f4ee9c3e02467d21845afe3088278f15bb4888ac00000000

You will want to look at the output from this command, as this is the TxID for the transaction which you just sent:
94cdeeaf0ae8799392a88347863b4a2b3493c33cc5f3b5d12392ecda86dc1eb5

This transaction ID can be looked up in any Litecoin block explorer and is the proof that you send the transaction.

Behind the scenes

Behind the scenes there is a computer somewhere running the litecoin wallet and a script inspecting any transactions which come to the LTC-SMLY ATM address, Lcb1iTTGxHacPNK3rdZeyZY5y2wS7Bcn1z. In this particular case, the script generated transaction fe9a880c071d5a17bb0cebcbc2e92bf5a1ea77cdd0ebb9a45df21fff9b919627 on the Smileycoin blockchain. If you look this transaction up in a Smileycoin block explorer, you will see that a total of 69362.80 SMLY were sent to SMLY address BL6dZnnFMXZUGXKMZ3fcJm48Gz4DidYKzJ as requested above.

PS More detail

Getting a SMLY address

In the Smileycoin wallet click on Receive and then on Receive payment. This will show you a new SMLY address. A SMLY address always starts with a capital B. Your screen should show something like this:

We will use this one: BL6dZnnFMXZUGXKMZ3fcJm48Gz4DidYKzJ

The Litecoin debugging window

The Litecoin GUI on a Mac has a Help button which gets you into the Debug window where you can find the Console button. You should see something like this:

If you have some LTC in this wallet, you can simply type listunspent on the command line. That will show you all unspent transaction outputs or UTXOs which you have. Just pick one of these.

A typical UTXO looks like this
[ { "txid": "c7ee53dee8a23e1ab59af4de95648d966ba4dd8072eacee6fb54faf77e48174b", "vout": 2, "address": "LfhYbb6cQBS2Zdh1ieDWmg2Zk42LqBCJF9", "account": "", "scriptPubKey": "76a914e09a6843488e9aef8a34538a0a1d2eea780453c888ac", "amount": 0.40740803, "confirmations": 3, "spendable": true, "solvable": true } ]

The key items you are looking for are the amount, the txid and the vout.

The TxID is an identifier of a Litecoin transaction where you have received LTC, but a transaction typically contains multiple addresses (inputs and outputs). The vout is an identifier of the outputs from the transaction, which made it into your wallet. This output, which you are about to spend, will become the input to your next transaction.

In this example the TxID is c7ee53dee8a23e1ab59af4de95648d966ba4dd8072eacee6fb54faf77e48174b,the vout is 2 and the amount is 0.40740803 LTC.

Transaction fees

To see the typical LTC transaction fees needed, go to this site

SMLY transaction fees are (at the time of this writing) 1 SMLY per Kb.

More stuff

If there is interest, the underlying scripts can be made available.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!