PubChat - a smooth entry point for aspiring Shimmer devs

Multi
4 min readMay 24, 2023

--

Easy peasy

Starting with an easy project can be a great way to dive into the world of coding and gain confidence in your abilities. By selecting a project that aligns with your interests and matches your current skill level, you can begin to apply the concepts you’ve learned and see tangible results. Simple projects, such as PubChat, allow you to understand key programming concepts like functions, loops or caching. It’s important to remember that the journey of becoming a proficient coder is a gradual process, and starting with achievable projects helps foster a sense of accomplishment and motivates further exploration and growth. So let’s look at PubChat and why it is a perfect start for code beginners.

PubChat

PubChat is a simple script that constantly checks for payments made to a specific crypto address: smr1qztz2z8cj3ygtnv984pq9ldq3jssppkv94nhlkvvfr994qp26ye7g5h4ezd

If a valid payment is recognized, the program will make requests to the OpenAi API and returns the received response from OpenAi via a transaction to the original crypto address where the payment came from. Blockbytes has created a video showcasing it. Follow the YouTube link in the embedded Tweet to witness it in action.

One more loop?

The code is implemented using JavaScript and executed within a node.js runtime environment. It is a straightforward single code block, featuring a simple setTimeout loop as its core.

async function server() {
const checkForPayments = async () => {
/* sync account and get incoming tx */
await account.sync({});
const paymentsReceived = await account.outputs({
lowerBoundBookedTimestamp: timestamp,
outputTypes: [3]
});
/* find valid payment and prompt question */
const paymentFound = paymentsReceived.find((payment) => {})
if (paymentFound) {
// get prompt response
const response = await openai.createChatCompletion({})
// send payment
account.buildBasicOutput({})
}
/* repeat the process */
setTimeout(checkForPayments, 1000);
}
checkForPayments();
}
server();

Crypto communication for the win

The wallet.rs library is used to recognize payments, which can be the most challenging aspect when starting this project. With wallet.rs you have the ability to create Shimmer accounts similar to setting up a wallet/account within the Firefly wallet. Once an account is established, you can utilize methods like sync() to ensure your account is up-to-date, outputs() to identify payments or buildBasicOutputs() to make transactions.

As the program solely relies on crypto transactions within the Shimmer network and doesn’t involve web or HTTP communication, there is no need to open ports or make the application accessible online. The wallet.rs library conveniently manages the typical API calls on your behalf, abstracting this functionality from the code base. Consequently, interacting with the Shimmer network becomes much simpler as you are shielded from the intricacies of web technologies.

Economics built in

Ai-SaaS-Entrepreneurs are currently grappling with the challenge of monetization. They need to develop a service that offers enough value to entice users into subscribing. However, if they are unable to achieve this, they face the dilemma of offering the service for free without incurring potentially exorbitant costs from OpenAI API calls or falling victim to spam and misuse.

On the other hand, PubChat does not encounter these problems because communication and monetization are inherently linked. When users send requests through PubChat, they automatically need to send a small amount of cryptocurrency (SMR) as payment, emphasizing the “pay-per-use” concept. There is no need to implement anti-spam measures. Additionally, there is no requirement for setting up a user management system where users first need to sign up or subscribe to use the service, emphasizing the project’s simplicity once again.

Conclusion

With the launch of PubChat, a very basic program, we overcame a few hurdles. The main hurdles are getting accustomed with the IOTA tech stack, which includes wallet.rs and iota.js. If you have any questions about this, you can hop on the Iota Discord and ask your questions in the #Development channel.

Currently, the primary challenge faced by PubChat revolves around the user experience. It is evident that transactions are taking too long, creating extended waiting periods in the wallet. This delay stems from the service’s requirement of two transactions — one for sending the prompt question and another for receiving the prompt response. Moreover, the Firefly wallet, which is used for these transactions, has not undergone frequent improvements and lacks crucial features such as selective text and an address book. This prompts us to consider how we can enhance the service and make it more user-friendly. In our upcoming blog post, we will delve into addressing the former issue by incorporating a functionality that ChatGPT currently lacks. Following that, we will tackle the latter concern: improving the user experience.

Follow the project: PubChat

--

--

Multi
Multi

Written by Multi

Auf diesem Blog geht es hautpsächlich um Kryptos (IOTA & SMR) und wie diese Technologien rechtssicher in unternehmerische Aktivitäten eingebunden werden können.

No responses yet