Hive dApps: Can ChatGPT Help Create Hive Applications?

Note: All responses to prompts come from https://chat.openai.com/chat

I've been learning some Python programming during the recent global pandemic. I am still a beginner learning from YouTube video tutorials and websites.

To be honest I am mostly learning Python so I can create at least one application on the Hive platform. Now that MemeHive and Hive Images are running I need to work on the legacy PAY token I brought over from "the other blockchain" after it forked and Hive was born. PAY is for @politicalhive and I have an idea for a political game I would like to make into a blockchain game which would use the #politicalhive token.

I think I've found a shortcut to help me. ChatGPT can generate text media as I've shown in a few recent posts. It can also generate programming code. Just like generated text I am sure that ChatGPT isn't 100% flawless but it's at least a good starting point for what I want to do.

Here's an example of some code I asked ChatGPT to generate using prompts. If anyone with more experience using Python can evaluate this code please leave a reply below. I am interested in how accurate ChatGPT can be generating code for Hive applications.

O.K. Let's say I wanted to create an application for users that wanted more anonymity and privacy of their Hive transactions.

image.png

Prompt: Can you write code for a cryptocurrency mixer for HIVE and HBD on the Hive Blockchain?

Sure, here is an example of how you can create a cryptocurrency mixer for HIVE and HBD on the Hive Blockchain using the beem library in Python:

import beem

# Connect to the Hive blockchain
hive = beem.Hive()

# Generate a new key for the mixer
mixer_key = beem.PrivateKey()
mixer_account = beem.Account(mixer_key, hive_instance=hive)

# Send some HIVE to the mixer account
tx = mixer_account.transfer("alice", 1, "HIVE", memo="Mixer deposit")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

# Get the list of UTXOs associated with the mixer account
utxos = mixer_account.get_account_history(start=-1, limit=-1)

# Select UTXOs to use as inputs for the new transaction
inputs = []
total_in = 0
for utxo in utxos:
    if utxo["op"][0] == "transfer" and utxo["op"][1]["to"] == mixer_account["name"] and utxo["op"][1]["amount"]["symbol"] in ["HIVE", "HBD"]:
        inputs.append({"txid": utxo["trx_id"], "vout": utxo["op"][1]["from"]})
        total_in += float(utxo["op"][1]["amount"]["amount"])

# Generate a new key for the recipient
recipient_key = beem.PrivateKey()
recipient_account = beem.Account(recipient_key, hive_instance=hive)

# Create the new transaction
tx = mixer_account.transfer(recipient_account["name"], total_in, "HIVE", memo="Mixer payment")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

This is just an example, and it is a very basic one, it will not cover all the functionalities of a real mixer, such as privacy enhancement and waiting for multiple confirmations before forwarding the coins, it should give you an idea of how to get started.

Please be aware that creating a cryptocurrency mixer may be illegal in some jurisdictions and might be considered as money laundering.

Also, take into account that in hive blockchain there is a 15 sec time window for the same account to do a new transaction, so you need to be aware of that and adjust the code accordingly.

So this is a simplified version of what would be a real application. I could write a prompt to describe my idea for a political blockchain game and probably get some code but I need to learn more programming before using it. I would want to make sure that my game idea is secure on the Hive blockchain.

ChatGPT can also add to code using additional prompts. If I were to run an application like this it would make sense to also charge a fee for using the application. Maybe it's because I am just a beginner but I don't see anything in the generated code example about charging fees so I should ask ChatGPT if it can add that to the code.

image.png

Prompt: Can you add to that code a 1% user fee for using the mixer that goes to the mixer account?

Sure, here is an example of how you can add a 1% user fee for using the mixer that goes to the mixer account:

import beem

# Connect to the Hive blockchain
hive = beem.Hive()

# Generate a new key for the mixer
mixer_key = beem.PrivateKey()
mixer_account = beem.Account(mixer_key, hive_instance=hive)

# Send some HIVE to the mixer account
tx = mixer_account.transfer("alice", 1, "HIVE", memo="Mixer deposit")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

# Get the list of UTXOs associated with the mixer account
utxos = mixer_account.get_account_history(start=-1, limit=-1)

# Select UTXOs to use as inputs for the new transaction
inputs = []
total_in = 0
for utxo in utxos:
    if utxo["op"][0] == "transfer" and utxo["op"][1]["to"] == mixer_account["name"] and utxo["op"][1]["amount"]["symbol"] in ["HIVE", "HBD"]:
        inputs.append({"txid": utxo["trx_id"], "vout": utxo["op"][1]["from"]})
        total_in += float(utxo["op"][1]["amount"]["amount"])

# Generate a new key for the recipient
recipient_key = beem.PrivateKey()
recipient_account = beem.Account(recipient_key, hive_instance=hive)

# Calculate the user fee (1%)
user_fee = total_in * 0.01

# Subtract the user fee from the total amount to be sent
total_out = total_in - user_fee

# Send the user fee to the mixer account
tx = mixer_account.transfer(mixer_account["name"], user_fee, "HIVE", memo="Mixer user fee")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

# Create the new transaction
tx = mixer_account.transfer(recipient_account["name"], total_out, "HIVE", memo="Mixer payment")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

This code calculates a 1% user fee for using the mixer by multiplying the total amount received by 0.01. Then it subtracts the user fee from the total amount to be sent and sends it to the mixer account using the transfer method. It waits for the transaction to be confirmed before creating the new transaction to the recipient.
Please note that, as mentioned before, in Hive blockchain there is a 15 sec time window for the same account to do a new transaction, so you need to be aware of that and adjust the code accordingly.
Also, keep in mind that this is a simple example and there are many other things to consider when creating a cryptocurrency mixer such as privacy enhancement, waiting for multiple confirmations before forwarding the coins, and more.

As a beginner I like that ChatGPT doesn't just generate code but also detailed explanations. I don't know enough to be strongly confident that the information is precise but it seems accurate enough to be a prototype.

This example is still missing something though. I need a name for it that's cutting-edge, like CutCo, EdgeCom, Interslice. Come on, Hive community, you're good at these! Help me out!

"How about... Bee Swarm?"

Fine, it's not important.

Prompt: Give the mixer the name "Bee Swarm" in the code.

Sure, here is the updated code where I've added "Bee Swarm" as the name of the mixer:

import beem

# Connect to the Hive blockchain
hive = beem.Hive()

# Generate a new key for the mixer
mixer_key = beem.PrivateKey()
mixer_account = beem.Account(mixer_key, hive_instance=hive)

# Send some HIVE to the mixer account
tx = mixer_account.transfer("alice", 1, "HIVE", memo="Bee Swarm deposit")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

# Get the list of UTXOs associated with the mixer account
utxos = mixer_account.get_account_history(start=-1, limit=-1)

# Select UTXOs to use as inputs for the new transaction
inputs = []
total_in = 0
for utxo in utxos:
    if utxo["op"][0] == "transfer" and utxo["op"][1]["to"] == mixer_account["name"] and utxo["op"][1]["amount"]["symbol"] in ["HIVE", "HBD"]:
        inputs.append({"txid": utxo["trx_id"], "vout": utxo["op"][1]["from"]})
        total_in += float(utxo["op"][1]["amount"]["amount"])

# Generate a new key for the recipient
recipient_key = beem.PrivateKey()
recipient_account = beem.Account(recipient_key, hive_instance=hive)

# Calculate the user fee (1%)
user_fee = total_in * 0.01

# Subtract the user fee from the total amount to be sent
total_out = total_in - user_fee

# Send the user fee to the mixer account
tx = mixer_account.transfer(mixer_account["name"], user_fee, "HIVE", memo="Bee Swarm user fee")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

# Create the new transaction
tx = mixer_account.transfer(recipient_account["name"], total_out, "HIVE", memo="Bee Swarm payment")
tx.commit()

# Wait for the transaction to be confirmed
tx = hive.wait_tx_confirmation(tx)

In this code, I've added "Bee Swarm" as the name of the mixer in the memo field of the transfer method, where it says "Bee Swarm deposit", "Bee Swarm user fee" and "Bee Swarm payment". This is a way to help identify the transactions related to the mixer.
Please note that, as mentioned before, in Hive blockchain there is a 15 sec time window for the same account to do a new transaction, so you need to be aware of that and adjust the code accordingly.
Also, keep in mind that this is a simple example and there are many other things to consider when creating a cryptocurrency mixer such as privacy enhancement, waiting for multiple confirmations before forwarding the coins, and more.

Of course, just like @politicalhive this kind of application would need a frontend for users. This makes me want to learn even more programming. It doesn't seem like such a huge obstacle now and besides a blockchain game for @political I can probably come up with a few more ideas that might get me some passive income on the Hive platform using ChatGPT.