Petrol Token
Build a token tied to the price of petrol
In nine chapters you build Petrol Token: a test digital coin worth one litre of petrol. Every morning the price is read from Italian filling stations and written on the blockchain, so anyone can see where the number comes from.
You do not need to program to follow the ideas: every chapter starts from an everyday picture. If you want to build it, each chapter has a short piece of code and one thing to try, and in an afternoon you reach a working version.
Everything happens on Polygon Amoy, a test network where the coin (POL) is free and worth nothing. That is why you can make mistakes without losing money.
Try it live
Before reading you can try the finished result (on a test network, no real value):
How to use the tutorial
- Read in order: each chapter builds on the previous one.
- Always do the "Try it" part: it is the fastest way to understand.
- The code shown is a simplified version, but the function names are those of the full project.
After the nine chapters, "Build your own basic version" guides you to rebuild a reduced, working version on your own computer.
Contents
- 1. Why an oracle
- 2. The Ministry's open data
- 3. The wallet and the test network
- 4. The price contract
- 5. The token with OpenZeppelin
- 6. Buying and selling
- 7. The program that brings the price every morning
- 8. The web page and MetaMask
- 9. Putting it all online on the test network
- Frequently asked questions
- Extra: build your own basic version