Build an Ethereum Transaction With Chat GPT Plus.
Introduction
In article 4 of the Blockchain Technology (TB) series, we explained a JavaScript program that allows me to build a transaction on the Ethereum blockchain and then send it to the Ethereum Virtual Machine (EVM) and transfer an amount of ETH from one account to another.
To build an application, the TB developer usually does it in stages:
First stage: select an IDE (integrated development environment), which is a software application that helps programmers develop code efficiently.
Second stage: conduct an Internet search for "open" source applications, such as the application you intend to develop.
Third stage: You start building the code segment by segment, programming and executing the code until you finally get it to work.
In this article we will make the following inquiry:
"What is the possibility of building a JavaScript program to execute an ERC20 cryptocurrency transaction, between two Ethereum addresses or accounts using artificial intelligence (AI)".
Technological tools or resources to use.
Chat GPT Plus:
Chat GPT (Generative Pre-trained Transformer) is an artificial intelligence (AI) model that:
Is a language specifically trained to answer questions and hold conversations with users.
Is a deep learning neural network architecture used to generate text.
VS Code:
Visual Studio Code is a source code editor developed by Microsoft. It is free and open-source software, available for Windows, Linux and macOS.
Git Bash:
It is a command line or terminal interpreter for Windows operating systems that includes Git. Git is an open-source version control system that allows users to track changes to a project's source code and collaborate with other developers on the same project.
Remix from Ethereum.org:
Remix is a browser-based IDE (Integrated Development Environment) for developing and testing Ethereum smart contracts, it provides an intuitive and easy-to-use user interface for writing, compiling, and debugging smart contracts.
Web3 and ethereumjs-tx libraries:
In programming, libraries are predefined sets of code that are used to perform specific tasks in a particular language, in the case of JavaScript, libraries are collections of code that are used to simplify and speed up the web development process:
Web3.js is a JavaScript library used to interact with the Ethereum network.
It provides some functions to perform tasks such as connecting to an Ethereum node.
Sending transactions to the Ethereum network.
Interacting with smart contracts and much more.
Ethereumjs-tx is a JavaScript library used to create and sign transactions on the Ethereum network, which:
Contain information such as the sender's address and the recipient's address.
The amount of ether or ERC20 tokens being sent, and any other data needed to perform a transaction on the Ethereum network.
Goerli Testnets:
Goerli is an Ethereum testnet that is used to evaluate applications and smart contracts in a secure and risk-free environment. The Goerli testnet was launched in March 2019 and is one of several Ethereum testnets that are available to developers.
Goerli Etherscan:
A block explorer and transaction analysis tool for the Ethereum Goerli testnet, it allows users to explore and analyze the Goerli blockchain in real time.
Public and private keys:
Who sends the funds:
Address: 0x30D752489CF27652fcc2553AAaaB2D5DD9359C80
Private Key:
6ace6d753edc427e6159e6b1529383c39f296778cb1310821bcabb397b13335b
Who receives the funds:
Address: 0x2586C4aa8Fccb20aacCe69a75a27726072C560BA
Private Key:
d35a217750bac528a5d4fbcd88b3f2e974ca28efcf2b78554d17479b8132c4fd
Note: Private keys must remain secret.
Funds to transfer:
For educational purposes we have created a cryptocurrency especially for this research, so that anyone can check the content of the article:
Name: YEN_Educational Digital.
Symbol: JPY_edu.
Supply 50,000,000 JPY_edu.
Smart contract address: 0xdeE034854c5eaba0c697c4527CBeC5F80C5c7f3e
Creation of the Tx with AI
Note: To facilitate the description of the article:
Tx means transaction.
We will call Chat GPT Plus GTP.
The queries to GPT will be made in English so that the instructions of the programs are returned in this language, which is the most used in programming.
Step 1.- We ask GPT (see red arrow in the image below):
An Ethereum transaction with web3 where address: 0x30D752489CF27652fcc2553AAaaB2D5DD9359C80 sends 100 ERC20 tokens to address: 0x2586C4aa8Fccb20aacCe69a75a27726072C560BA.
GPT gives us a JavaScript program as a response (see yellow arrow).
Step 2.- We copy the program in the VS Code editor:
Step 3.- We analyze the first instructions of the program:
On line one the program requires the web3 library. We enter the website3, and it tells me (see blue arrow) that the version of the library was updated or released 2 months ago:
On line two it requires the ethereumjs-tx library. We enter the ethereumjs-tx site, and it tells me (see green arrow) that the version of the library is obsolete (a library is abandoned when it presents certain vulnerabilities).
Observation:
The Chat GPT Plus version was formed with Internet content available until the end of 2021, and ethereumjs-tx was replaced by the ethereumjs/tx library at the end of February 2023 (see orange arrow image below):
Step 4.- Input values or constants:
Line 5: connection to a public node of the Goerli network.
Lines 8 and 9: the private key of the sender of the funds.
Lines 10 and 11: the address that you send and the address that receives the funds.
Lines 12 and 13: the amount of cryptocurrency to send (100 JPY_edu) and the address of the Smart contract that created the cryptocurrency.
Step 5.- Application of binary interface (ABI):
Line 14: The ABI of an Ethereum token is code that contains a list of functions available in the contract (in binary format), as well as the data types required to call those functions and the data types returned by them.
The ABI of a token is obtained from the IDE in which the ERC20 token was implemented. In this case the IDE was Remix from Ethereum.org (see red arrow, image below):
Note: The ABI occupies line 14 to line 297 of the VS editor.
Step 6.- Execution of the program:
Now we will study the rest of the code from line 298 to 318 where we proceed to structure, sign, and send the Tx:
Step 7.- Structuring of the Tx:
Lines 301 to 308 structure the object transaction (Tx in JSON format). Running this part of the program in Git Bash (the command line terminal) we get the txObject:
Step 8.- Creation and signing of the blockchain transaction:
In lines 309 to 311 the ethereumjs-tx library is used to create and sign the txObject on the Ethereum network.
When running this part of the program in Git Bash we get an error (see yellow arrow) that says:
Error: Expected private key to be an Uint8Array with length 32
Step 9.-We consult GPT about this error, and it suggests a change in the code:
We apply the change, run the program again and the error remains (see green arrow):
Error: Expected private key to be an Uint8Array with length 32
Note: We continue to apply other changes, we even consult GPT about the new @ethereumjs/tx library (see red arrow) and it always returns a code with the obsolete library (see yellow arrow) that maintains the error when executed.
Step 10.- Problem:
Since the problem is that the JavaScript program uses a library that is already obsolete and GPT does not give me a program with the new library, because it does not know about it (it was not available in 2021), I must look for a program that doesn't use this deprecated library, but keeps most of the original instructions that GPT gave me.
Step 11.- Another solution:
We search the internet for "open source" code applications, like the one we intend to develop.
The first part of the program where we already entered the data remains the same.
The second part looks like this:
Step 12.- successful transaction: When executing this part of the program in Git Bash we obtain the confirmed transaction in the Ethereum goerli blockchain. This transaction is identified with the hash (see blue arrow):
0xeb36fabcc1e33cea12bc920df573de6498aafd598440d9f4909b348fbb433148
Step 13: We can view the transaction in the goerli Etherscan explorer:
The hash of the Tx (red arrow).
The address that sends and the one that receives the funds (yellow arrow).
The amount of one hundred units of the YEN_Digital token (green arrow).
Final remarks:
Building a transaction to send an ERC20 token transaction between two addresses, consulting the artificial intelligence application GTP Chat Plus, we concluded that:
Usually, searching the internet for open-source code takes from 4 to 12 hours of work, on the other hand with GPG Chat Plus it was reduced to about 10 seconds.
Once the GPT program is obtained, we must run it segment by segment as the developer would do with or without GPT. There is no difference here.
The fact that the "ethereumjs-tx" library is deprecated and that GPT could not give us an adequate answer, indicates that the artificial intelligence has limitations of the content it was trained with.
It is possible that the latest version to be released, GPT 4, may overcome these technical issues.