Inspiration
As a mechanical engineer I do a lot of scientific computations. The question set out with this project was to determine whether or not a blockchain could be used in some way for this purpose. In statistics a random walk is a way to explain Monte Carlo simulations, where the latter employs lots of random number generation. Chainlink VRF Oracles allow a blockchain-generated random walk to be verifiably random
What it does
It generates a plot of n number of nodes as set by the user. The smartcontract computes all n nodes by traversing a random walk which is forward biased for all nodes after 0 (walk somewhere forwards instead of walk anywhere completely randomly). The frontend gets the unique plot data from an NFT and plots it in Python's Matplotlib within the browser. With some style effects, the plot looks sort of like a treasure map.
How we built it
The smartcontracts were developed and compiled using Remix. A library that allowed approximations to trigonometric functions was needed. The library FixidityLib was used as Solidity does not natively support fixed-point arithmetic. The rest was designed in VS Code.
Challenges we ran into
- FixidityLib has seemingly been abandoned and was on Solidity version 0.4.0, so I had to fix bugs to allow it to be compiled with newer compiler versions.
- I thought at the beginning of this project that I could just run a Python-created executable from the HTML page or with JavaScript. This was not the case, but luckily I managed to incorporate Pyodide which installs Python and various scientific libraries into the browser when it is loaded. It loads slow, but it got the job done.
- It really is a bad idea to try and generate multiple random numbers and compute complex Taylor-series expansion approximations to the trigonometric functions in mathematics within Solidity. The gas prices were incredibly high even just for 60 nodes in a walk. I had to limit the nodes to 40 in the frontend because otherwise the gas limit gets reached on certain days and then the NFT cannot actually be generated at all. Perhaps some inline-assembly could optimize the approximations I used, but I don't know assembly.
Accomplishments that we're proud of
- Finished my first big blockchain and full-stack project.
- Successfully incorporated a statistical model into a blockchain with a smartcontract.
- Found a way to get Python into a browser, and got it to work with what I needed.
What we learned
I learned how to use: Git, HTML, JavaScript, Solidity, and how to bring different environments and programming languages together to create a full-stack project.
What's next for Random Walk NFT
The way the smartcontract generates the random walk is hilariously expensive on gas. I can't really think of a way to get it better, but it's possible that with optimizing it, we would gain some mathematical tools within the blockchain that can be used as a library for other projects.
Built With
- html
- javascript
- npm
- openzeppelin
- pyodide
- python
- solidity
- vscode
Log in or sign up for Devpost to join the conversation.