TinyQR is an app that lets you create tiny links out and QR codes from long ugly URLs.
The web app deployed at tqr.lol, interacts with a smart contract deployed on the Polygon Mainnet.
1.) Users make a transaction requesting the blockchain to store a URL string.
2.) Since it is a transaction that modifies the state of the blockchain, it needs to have some fee(also called gas) attached to it so that it can be mined to the blockchain by miners.
3.) There is some waiting time for the transaction to be confirmed (5–10sec) depending on how busy the polygon blockchain is.
4.) The shortened URL is generated. eg this short URL https://tqr.lol/t/0x04 redirects to this mirror blog post.
5.) When the users clicks on the shortened URL another transaction is made requesting the blockchain which URL string is located at the provided reference. Since this transaction is not changing the state of the blockchain, we do not need to pay any gas fee this time, the user is seamlessly redirected to the long URL.
Here’s the smart contract source code
pragma solidity ^0.8.0;
//SPDX-License-Identifier: MIT
contract e0x {
event Log(string message);
event LinkAdded(uint linkId, string url);
struct LinkTemplate {
address userAddress;
string url;
}
uint lastLinkId;
mapping (uint => LinkTemplate) public linkMapping;
constructor() {
lastLinkId = 0;
}
function createNewLink(string memory url) public returns (uint) {
lastLinkId++;
linkMapping[lastLinkId] = LinkTemplate(msg.sender, url);
emit LinkAdded(lastLinkId, url);
return lastLinkId;
}
modifier linkExists(uint linkId) {
//link with the given hash does not exist
if(linkMapping[linkId].userAddress == 0x0000000000000000000000000000000000000000) {
revert();
}
_;
}
function getLink(uint linkId) public view
returns(
address,
string memory
) {
LinkTemplate memory link = linkMapping[linkId];
return(
link.userAddress,
link.url
);
}
}
Check it out at
Smart contract source code (on polygon scan):
web app source code (on github)
Pull requests are welcome if you want to build on top of tinyQR
Also, 100 mints on mirror for this article and we will launch on Optimism :)