Interaction between a Polygon and Ethereum Smart Contract
How to call a Polygon Smart Contract from your Ethereum Smart Contract.
For the last 3 months, we have been working on a new Web3 project, Chessverse. When Chessverse started, our thought process was similar to any standard Play to Earn Games that have been launched.
This would have been very interesting, in 2021. None of us in the team have actually launched a Web3 project in the past. Hence we wanted to use this experience as a learning opportunity as well. That is when it hit us that if we truly want to make the NFTs unique in true sense, we should somehow reflect the Win/Loss Data on the NFTs.
That led to the Version 2 of the workflow where we added a Centralised server to fetch the Win/Loss Data
Do you see the problem? Well, to start with this is a Web3 project. And the majority of the components looked like Centralised, which would result in users doubting the system eventually. We wanted to minimise the Centralised components so that we could build more trust around the project. To do this, we decided to move the Win/Loss data to a Smart Contract.
This started to make real sense and would have been a great project to work on, until Gas Fees hit us!
We started looking for alternatives and thought of a theoretically exciting idea. What if we could have the Win/Loss Metadata on a Polygon SmartContract. That way every time we have to update the Metadata, we are not burning a hole in the pocket.
This idea was exciting for the whole team. We started looking for answers and tried a few different routes. Obviously the first one was to directly try to link the Polygon Smart Contract to Ethereum Smart Contract and pray they worked together. 😂
The second one was to use Graph. But after many tussle and failed attempts with Graph, we were not very satisfied with the implementation. It then clicked us that this is just one contract that we are interacting with and we do not need to actually set up an elaborate setup like Graph or any other index for connecting the two Contracts.
That, plus some tutorial from buildspace, led us to a hack which we thought just might work.
We deployed our Win/Loss Metadata contract on Polygon and added a Node Wrapper around it. This Node Wrapper does nothing but fetches Metadata from the Polygon Contract and passes it onto the Ethereum Contract.
And voila!
Thus, we now have our NFT contract deployed to Ethereum and the dymanic metadata comes from the Polygon contract which is getting updated frequently.
If you are interested to know more, do join us at https://www.chessverse.club/
I am happy to answer any questions on our discord.
P.S: For those interested here are the links
Leave a Reply