Coding Coding part: build your own basic version of Petrol Token, step by step, with commands to copy. Open the Coding page
Name on the chain. the contract is named FuelToken and its symbol is FUEL; that is how you find it on Polygonscan, in MetaMask and in the code of the chapters.

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.

Petrol Token is a teaching demo on a test network: the tokens have no real value.

Try it live

Before reading you can try the finished result (on a test network, no real value):

How to use the tutorial

After the nine chapters, "Build your own basic version" guides you to rebuild a reduced, working version on your own computer.

Contents

  1. 1. Why an oracle
  2. 2. The Ministry's open data
  3. 3. The wallet and the test network
  4. 4. The price contract
  5. 5. The token with OpenZeppelin
  6. 6. Buying and selling
  7. 7. The program that brings the price every morning
  8. 8. The web page and MetaMask
  9. 9. Putting it all online on the test network
  10. Frequently asked questions
  11. Extra: build your own basic version