fbpx
How I use AI in Blockchain

These AI skills will 10x your Blockchain career

Julien Klepatch

Today I am going to tell you how I use AI to boost my productivity as a Blockchain developer.

My first steps with AI

Ok, I have to admit, I am late to the party.

When AI started to be popular, I was very skeptical. I thought it would be just another hype, and in a few month it would be gone. So I ignored it.

But it didn’t stop. Everyday, on Twitter, you see another account who goes like “Oh, AI is going to change the world blabla”.

At some point, I was like, ok, let’s give it try. So I created my chatGPT account, and…. it was ok… but nothing too crazy. It could do basic coding tasks. But often it was wrong. So I wasn’t really impressed.

Until…something happened. Until I tried Cursor AI.

Cursor AI is this new code editor with AI features, and this blew my mind. And after I started to force myself to use all the AI tools, Claude, Perplexity, etc… And now I can finally say, yes. This stuff is good. It doubled my productivity. You have to use it.

So I am going to tell you which tools I use, and how I use them.

AI tools for Blockchain development

Let’s start by which AI tools I use:

  • Claude
  • Perplexity
  • Cursor AI
  • v0

I use Claude for code generation. For coding and writing tasks, Claude is the best. Before, I was using chatGPT for the same tasks, but Claude is much better. The code produced by Claude is higher quality, and it understands what I want to do.

The UI is also better. The different artifacts that it produces are separated and versioned, which makes it easier to follow what’s happening, contrary to chatGPT where everything is in the conversation thread.

I use Perplexity to research some new protocol. It’s very good at analysis. It shows you its sources and it can also get real-time data, contrary to Claude and chatGPT. This is very important for software development and Blockchain where everything moves so fast.

I use Cursor AI to write code. Cursor AI is a clone of VS code with built-in AI. It’s main feature is a smart autocomplete. It’s similar to Github copilot but much better. You start coding something, then it will make a smart suggestion for the rest. It’s very smart. It understand very well what you want to do. Sometime you find yourself just doing a series of tab tab tab to accept all his suggestions, and it’s very fast.

I was able to code in languages I didn’t know. For example, for the new Blockchain education platform I am working on, the 30 day academy, I used Ruby on Rails, that I don’t know very much, but with Cursor AI, no problem at all. Since I use Cursor AI, I don’t use Claude as much as before, because Cursor.

There is another feature of Cursor AI that I haven’t tried but that seems very powerful. It’s called Composer, and it’s basically a way to. generate a whole codebase from your prompt. And there are tons of other cool stuff you can do with it. I am just a Cursor AI beginner, and it’s already made me so productive, so you should try it.

Finally, I also use v0 for generating frontends. v0 is a tool built by Vercel, the company behind NextJS. ChatGPT and Claude can also generate code, but v0 is specialized just for code generation, and even more specifically, frontend code. They have a UI where you can switch between the code and the visual rendering. Great stuff.

Coding smart contracts with AI

The first use case for AI in Blockchain is coding smart contracts.

For example, you can tell the AI:

Generate a Solidity smart contract for a deflationary token with:

*   2% burn on each transaction
*   Anti-whale mechanism
*   OpenZeppelin security standards

And this is typically something I would do in Claude, at least for the first version.

After I would take this to Cursor AI.

In a Blockchain app, there is also a frontend, and you can also use AI for that. For frontend code generation, I would start in v0 with a prompt like “Generate a React component with a button to mint new tokens of a ERC20 smart contract. This is the interface of the contract”.

And then, once I am satisfied, I would also take this to cursor AI.

Be very specific in your prompt. You want to specify

  • A general description of what you want
  • Specific details, like this smart contract should have a function for this, a function for that
  • And finally, which technology you want to use, like Solidity, or React.

The more details you give it, the better your code.

Testing smart contracts with AI

Another great use case for AI is testing smart contracts.

For example, you can ask it:

Create tests for this smart contract using the Foundry framework. Make sure to reach 100% code coverage, covering all the happy and unhappy path. Group all tests of a function in a separate test contract

And then you paste your smart contract.

So yes, you can use AI recursively:

  • AI a first time to create a smart contract
  • You take the output and feed it again to the AI a second time to test it

AI is very good at testing, because it’s a problem very well specified. The code you are testing is part of prompt. So It has a lot details, and it usually does a great job.

And this is something that you can verify very easily. Just copy paste those tests into your Foundry project

  • Make sure the test pass
  • And you can also get the test coverage with a Foundry command
  • So if all the test pass, and the coverage is 100%, well, congratulations, the job is done

Refactoring smart contracts with AI

Another great use case of AI for Blockchain development is refactoring smart contracts.

Let’s say you have coded your smart contract, and you have this huge block of code, several 100 line of code. And you look at it, and you are not happy.

You are like: hey, there is too much going on here. We need to simplify this code. We need to split into different smart contracts. We need to make it look better.

You can use AI for that. For example, the prompt can be:

Refactor this smart contract into several smart contracts each focused on a specific task. The new code should be easier to understand

Or it could also be a little higher level, like

Suggest 3 different ways to refactor this contract

And then once you have identified an option you like, you prompt it again with some more specific instructions.

Generating smart contract documentation with AI

Let’s say you have your smart contract ready, and you want to create some documentation.

And you can even ask for a specific type of documentation.

For example, the prompt can be:

Add documentation to this smart contract, using the Natspec format

And then you have to copy paste your contract.

Or if you want to create a README, the prompt can be

Create a readme for this project with sections on how to get started and how to run tests

Gas optimization with AI

Let’s say you finished your smart contract, and you want to make sure that it’s as gas efficient as possible.

The prompt could be:

Suggest some gas optimizations for this smart contract. Show the code before and after, with the line numbers

Smart contract audits with AI

Another great use case of using AI in Blockchain is smart contract audits.

Let’s say that you coded a smart contract, and the next step is a security audit.

Before giving your smart contract to a security auditor, you want to make sure you already removed all the easy vulnerabilities.

Your prompt could be:

Do a comprehensive security audit of this smart contract. List all vulnerabilities and how to fix them

Debugging smart contracts with AI

The next use case of AI in Blockchain is debugging smart contracts.

Let’s say you have a test that is failing. And you don’t understand why.

You can get some help from Claude. The prompt can be:

Explain why my test is failing, and how to fix the test

And then you would copy paste all the required context, the smart contract code, the test, and the error message.

Transaction analysis with AI

The next use case of AI for Blockchain development is transaction analysis.

For example, you want to understand a recent hack, but you don’t understand the transaction, because it’s complex.

What you can do is:

  • Go to a tool like tenderly
  • Paste the transaction hash. It will get you an execution trace
  • Then your prompt Claude to explain you this transaction:
Explain this transaction using simple sentences. 
Describe each step with a simple sentence:
  * which is the calling contract
  * which is t he called contract
  * and what was the action

And you provide the execution trace.

Use AI to explain Blockchain protocols

The next use case for AI in Blockchain is to understand protocols.

Let’s say there is a new hot protocol that you want to understand.

You can use Perplexity for this. The prompt can be:

Explain me in 500 words what this protocol does

And you can also use it to understand the code of a smart contract.

Use AI for content creation in Blockchain

I don’t think many developers would have this idea. But it’s one of the best use case.

I often mention how nowadays every developer should be active on social media. That’s a great way to build your personal brand and get the attention of recruiters. For example, on LinkedIn, you can share coding tips.

And you can use AI for that:

  • Claude is the best for writing tasks, but it cannot access the internet in realtime.
  • And Perplexity is great for analysis and it can access the internet in realtime.

To create up-to-date content you can:

  • First use Perplexity to do an analysis about some coding topic
  • Then you copy paste this analysis to Claude and ask to reformat it in an article

And that’s how you can create an article very fast.

Conclusion

There is no need to be afraid of AI:

  • AI is your friend.
  • AI will make you much more productive

So, better get on board as soon as possible!

On November 29th, I am launching a brand new Blockchain academy, the 30 Day Academy. This is going to a course platform based on challenges. You will have one challenge per day, for 30 day.

And for the launch on Black Friday, I am going to do a special deal. To receive this deal, register with this link. All right, that’s it for today bye

0 Comments

Leave a Reply

More great articles

The Ultimate Solidity 0.8 Cheatsheet

Comments You can write comments to document your code; Single-line comments (//) and multi-line comments (/.../) are possible. // This…

Read Story

Smart Contract Security Roadmap

In 2021 $1.5 billion were hacked from smart contracts. That’s why smart contract security experts are in high demand and…

Read Story

How to store your NFT metadata

I will be addressing these issues in this article. More specifically, we will show you how to: Upload Images to…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up