The other tool relevant for our use case is Remix IDE:
The Remix Project is a rich toolset which can be used for the entire journey of contract development by users of any knowledge level, and as a learning lab for teaching and experimenting with Ethereum.
remix-project.org
In practical terms, Remix allows anyone to develop, test and deploy smart contracts right from the browser (using a Metamask wallet) without having to install anything.
By leveraging ChatGPT’s text-to-code capabilities and Remix’s testing and deployment features, developers gain access to a powerful toolset for rapid prototyping and validation.
Let’s outline the steps from idea to deployment on the blockchain. The goal is to create a smart contract that distributes a specific token to different wallets every day. The quantity of the token received is based on the score associated with each wallet (those with higher scores will get more tokens).
Our experience with ChatGPT suggests that it is more effective to start with the most basic version of a solution and gradually inquire ChatGPT to include more features. It is as if we were executing a condensed product roadmap in a few hours.
For the first prompt, we ask ChatGPT to “Code a solidity smart contract that distributes ETH into a list of wallets every day”. The response is as follows: “Sure, here’s a sample Solidity smart contract that distributes ETH into a list of wallets every day”
pragma solidity ^0.8.0;
contract DailyDistribution {
address payable[] public recipients;
uint256 public dailyAmount;
uint256 public lastDistributionTime;
constructor(address payable[] memory _recipients, uint256 _dailyAmount) {
recipients = _recipients;
dailyAmount = _dailyAmount;
lastDistributionTime = block.timestamp;
}
function distribute() public payable {
require(msg.value == 0, "Cannot send ETH to this function");
require(block.timestamp >= lastDistributionTime + 1 days, "Cannot distribute more than once a day");
uint256 contractBalance = address(this).balance;
uint256 distributionAmount = dailyAmount / recipients.length;
for (uint256 i = 0; i < recipients.length; i++) {
recipients[i].transfer(distributionAmount);
}
lastDistributionTime = block.timestamp;
}
}
As further iterations, we may inquire these questions that progressively incorporate additional features:
In parallel with the evolution of the contract in ChatGPT we can start testing (and deploying) the contract on Remix.
Open https://remix.ethereum.org, create a new file in the contracts folder, paste the code from ChatGPT and hit save. Errors will appear at the bottom if there are any; they can be copied and pasted back into ChatGPT for automated fixing.
Once ready to deploy, go to the “Deploy” tab, click “Environment” dropdown and select “Injected Provider - Metamask”, and click the deploy button 🚀
Using a testnet can be advantageous during development as gas fees will be free (e.g.: ethereum sepolia, polygon mumbai, gnosis chiado).
For faster code debugging, Remix can be used to call contract methods directly while working on the dApp frontend development.
Though most of the development of this smart contract with ChatGPT progressed without issue, that was not always so. When we requested a feature to make the transfer amount dynamic, the result produced by ChatGPT was incorrect due to an error in its calculations (an experienced eye can quickly scan the code and investigate any abnormalities).
We can query ChatGPT directly with: “Why are you dividing by the approvedRecipients.length in the distributionAmount calculation?”. ChatGPT will gladly explain why and provide an example of the output values of the calculations:
For example, suppose there are two approved recipients:
Recipient A with score 2 and Recipient B with score 1.
If the total amount to be distributed per day is 100 tokens,
then the calculation for `distributionAmount` would be as follows:
- Recipient A: `(100 * 2) / 3 / 2 = 33.33 tokens`
- Recipient B: `(100 * 1) / 3 / 2 = 16.67 tokens`
Examining the example, we replied to ChatGPT: “we want to distribute 100 per day, but in that example we only distributed 50”, to which ChatGPT apologised and amended the code.
We are excited about the potential of tools such as ChatGPT to further enhance our workflows and deliver greater value at a faster pace. As technology advances, Remix may even soon be able to directly integrate with ChatGPT. The efficiency benefits that this could bring are immense and we look forward to what the future holds. Streamlined processes will allow us to provide customers with the value they need on time, at a higher quality, and tailored to their individual needs; thus, leading to superior products and greater customer satisfaction.