DEV Community

Cover image for Shorten your link with my #Smartcontract.
MahaLakshmi Perumal
MahaLakshmi Perumal

Posted on

Shorten your link with my #Smartcontract.

Shorten the link #smartcontract has been deployed on #XinFin Network and the transaction fees to deploy this smartcontract was 0.00007 XDC. Let me know the transaction fees for deploying the same smartcontract on your #Network.

Here the #smartcontract:
pragma solidity ^0.4.24;
contract e0x {
event LinkVisited(string url, uint linkId);
event LinkAdded(uint linkId, string url);
struct LinkTemplate {
address userAddress;
string url;
}
uint lastLinkId;
mapping (uint => LinkTemplate) public linkMapping;
constructor() public {
lastLinkId = 0;
}
function createNewLink(string 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) linkExists(linkId) public constant
returns(
address,
string
) {
//emit LinkVisited(linkId, link.url);
LinkTemplate memory link = linkMapping[linkId];
return(
link.userAddress,
link.url
);
}
}

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
thorstenhirsch profile image

Using an incremental number (linkId) as the shortened URL lets any user "guess" all shortened URLs anyone has ever added, thus leaks all real URLs of your smart contract.

Also: please use tripple backticks (before the first and after the last code line) instead of single backticks (around each code line) for better visualisation of your code.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay