Hive dApps: Can ChatGPT Help Create Hive Applications?

in LeoFinancelast year

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.

Sort:  

I'm pretty sure that 15sec wait thing changed in the last fork.
Blocks are final instantly now.
Before there was up to like 9sec delay, but bt fixed that.

Oh, great. More mixing rounds for the same amount of time. 😁 I think you are right. Most of of what ChatGPT "knows" is current for around the year 2021. Of course, someone could just tell ChatGPT to tweak the code for that with an additional prompt. Not that i am condoning or encouraging anybody to do that and launch this as a real application. This is purely academic and code and an exercise that anybody can do with ChatGPT.

I did ask ChatGPT to generate a coinjoin script for the Hive blockchain. ChatGPT can give an example of a simple coinjoin script using JoinMarket for bitcoin but it doesn't know how to implement coinJoin on Hive so...the code in the post is purely academic. That's what I am sticking with.

Coders should be soon loosing that 'tude they been giving us for sooo long.
Their death knell is sounding.
Just like truck drivers, burger flippers, and buggy whip makers before them.

A mixer would obscure who sent what to whom?

Just as journalists (and I) were learning how to code.😢

O.K. I accepted the ChatGPT answer that it didn't know how to CoinJoin but after a few more prompts, maybe this has also changed since around 2021, I think I've learned that CoinJoin can''t be implemented because Hive's blockchain does not have UTXOs like bitcoin. Instead of deleting inputs and creating outputs for transactions Hive's DPoS only updates account balances with each transaction.

So instead of bitcoin's two options to increase anonymity crypto tumbling on Hive would be the only real option for anyone wanting to go from pseudonymous transactions to anonymous ones.

Where does zero knowledge proofs fit in?

I posted about that last year.

https://peakd.com/hive-167922/@holovision/math-behind-zero-knowlege-blockchain

For Hive and bitcoin it doesn't fit in. Zero proof blockchains are used by coins like Monero. Neither Hive or bitcoin are zero knowledge proof. If Hive were zero knowledge proof https://hiveblocks.com transactions would look more like https://moneroblocks.info transactions.

This is what ChatGPT says:

Monero uses a technique called "RingCT" (Ring Confidential Transactions) to obscure the amounts involved in a transaction and the identity of the sender. This technique uses a combination of ring signatures and stealth addresses to hide the origin and destination of a transaction.

Ah well, I guess we need a coin with transparency as much as one without.

The moment to buy some PAY

It's going to be a while. I am going to try to set a goal for launching the @politicalhive tribe right before the 2024 U.S. presidential election. That's in 647 days.

I've already used ChatGPT to help me with the programming at my current job as an automation test engineer. It is very good for simple tasks and coding, for complex things you need to think about it and put it all together. But I can already see a future where if you have a good idea the AI can help you step by step with building blocks.

Posted Using LeoFinance Beta

Breaking a big program down into parts is a good idea. I guess for launching an open source project having some code generated by ChatGPT is better than, "Hey, I have a cool idea but nothing as a protype."

Congratulations @holovision! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 105000 upvotes.
Your next target is to reach 110000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out our last posts:

The Hive Gamification Proposal
Support the HiveBuzz project. Vote for our proposal!