This article will go over:
- Leaderboard Contract: How the solidity contract works
- Remix: How to interact with the contract
- Metamask/web3 Wallet: To fund and deploy.
- Deploy on testnet.
leaderboardLength = 10will save the top 10
Usernames and scores
leaderboardis public so anyone can see the
useris a username like “Alice”
scoreis an number like 777
- The person who deploys the contract is the
ownerand is the only one allowed to update the leaderboard
addScoreis called to update the leaderboard
Remix IDE is used to create and interact with the leaderboard contract.
Click + to create a new file.
Paste in the code from above
Compile the code
Click the drop-downs, enter a user, score and click transact. The logs on the right should have a decoded output of true.
To fetch data, enter 0 into leaderboard (since we only have one input and code starts at index 0). User name and score should appear (Alice 777).
We have a working leaderboard. Feel free to add more users, test and experiment.
To deploy on mainnet/testnet we need fund a wallet and some ETH.
In this example, we’ll deploy on Rinkeby testnet.
Anyone having a Twitter or Facebook account may request funds within the permitted limits. Tweet/post your ethereum address on social media then use the link to receive testnet funds.
Change the environment to
Injected Web3 and make sure there are funds. Click
Add and get users from the leaderboard.
Congratulations! You created an ethereum leaderboard. This will set up the foundation for more interesting projects like decentralized games.