How can I run a truly serverless function on web3 type infrastructure?
- blockchain
- NFT
- solidity All Things Web3
I want to run a serverless function that is actually serverless. Serverless functions platforms like AWS Lambda, Google Cloud Functions, etc... are not actually serverless. A centralized VM owned by Amazon or Google runs the function. I usually make apps that consist of a static site that I host on IPFS connected to a Handshake domain. But I can't do this for certain apps that require dynamic functionality
I have this proof of concept express function. It's a simple anagram finder. It's a simple dumb express.js
function but it's just a proof of concept. I would connect this to the backend of a static site.
var express = require('express');
var router = express.Router();
router.post('/', function findAnagramsInArray(req, res) {
var words = JSON.parse(JSON.stringify(req.body));
let result = {}
for (const word of words) {
const sorted = word.split("").sort().join("");
if (sorted in result) {
result[sorted].push(word);
} else {
result[sorted] = [word];
}
}
res.send(result);
});
module.exports = router;
Could this be run in a decentralized trusted compute environment? I've tried Akash but this isn't really ideal because it's a deal id based service. I believe that the URL for the function changes when you renew the deal. This won't work with an IPFS static site because you have to change the connection string for the function, this changes the CID which bricks the website connected to the Handshake domain.
I tried Thirdweb and Moralis and these work but they're actually still centralized in the sense that they still run on privately owned servers like with Amazon Lambda functions. No shade to Thirdweb and Moralis. I actually love these providers it's just not what I'm looking for in this particular question.
I tried Aleph.im's "aleph-vm" functions and this is the best one I've found so far. It actually does work, but I think it only runs python code. The code I want to run is javascript (more specifically typescript). I ported my proof of concept code to python and it worked perfectly but my real code (which I'm keeping private for now) contains npm libraries that don't exist in python.
I recently heard of Gelato functions but it's currently in a private beta (I don't have access).
I also got really close using Fluence Network. It's really interesting and I think it runs serverless functions on public infrastructure. I got soooo close but it appears to have the same problem as Akash in the sense that deals expire and need to be renewed. I think renewing a deal creates a new URL which could brick my static site that calls out to a hardcoded url. Also, the typescript compiles to bytecode for something called aqua vm before it deploys, so I don't think that it allows importing external npm libraries. This kills my main use case for my private code.
Another acceptable solution would be if there's a decentralized way to run Next.js apps that contain functions in the pages/api/
folder. I think that if you run a Next.js app with a function in the pages/api/
directory, Next.js runs that code in a vm that accepts ajax calls from the static pages. That's why you can't compile a Next.js app to a strickly static app if there's code in the pages/api/
folder. Maybe there's a decentralized version of Vercel which can simply deploy a Next.js app with a pages/api/
function?
So what am I missing? Is there a way to run serverless function code in a decentralized manner with a persistent connection string?
Answers 1
This is a very interesting topic. We are considering a decentralized serverless functions solution for various tasks at Peeranha to simplify logic in the smart contracts or to replace centralized components that currently run as AWS Lambdas. Thank you for sharing your research in such detail.
Chainlink functions are the solutions that look very promising: https://chain.link/functions They are currently in Beta but it is possible to apply for early access.
Another very interesting project that allows running verifiable tasks in a decentralized environment is Koii Network - https://www.koii.network/ More details here - https://docs.koii.network/microservices-and-tasks/what-are-tasks
-
This is a great answer! Chainlink functions look really promising! Also Koii Tasks are completely new to me but they seem to be a great solution for decentralized computing