Building a Blockchain Inside a Subgraph

Hi folks!

I wanted to share something I hacked together yesterday. For context you can see my tweet thread here:

Basically I got it into my head to build a blockchain inside a Subgraph. I built a proof of concept which is rough, it’s just a Token that allows you to create a token and transfer it, but the concept is there.

The Github:

The Subgraph:

What I’m doing here is using a simple smart contract by Auryn.eth as a “portal” on L1 Ethereum.

The contract looks like this:

    function post(string memory content) public {}

What I do is send to the the function a JSON message object with instructions for the subgraph.

So, to create a token:

{"operation": "CREATE","supply": 1000,"name": "Test Token Name"}

And to transfer a token:

{"operation": "TRANSFER", "token": "Test Token Name", "recipient": "Ethereum address here", "amount": 50}

The subgraph reads and parses the message and figures out what to do with it.

Right now the design is simple, but the concept I’m proving here I think is really amazing.

We can put various “programs” in a subgraph that latch on the operation value of the JSON object. Then we can have arbitrary code that processes the data in the JSON object.

So this is a Token, but we could easily do NFTS, (with rich metadata built into the subgraph!), we could do an AMM for Tokens, Social media, etc… The great part is that:

Deterministic ordering of messages provided by L1 Ethereum
“Mining” by Graph protocol Indexers
Query Fee’s paid in GRT
Curators which identify the “Canonical” Subgraph
Forks which simple add new programs on the same deterministic data chain
Awesome GraphQL endpoint for the data.

We can upgrade the subgraph via a DAO on L1 which would point to the Canonical Subgraph, but folks would be free to choose different subgraph version if they wanted different programs or different programmatic functionality.

Everything is written in Assembly script!

Wild no?


Sounds interesting :+1:
Thanks for sharing.