DEV Community

loading...
Cover image for Shorten your link with my #Smartcontract.

Shorten your link with my #Smartcontract.

mahalakshmiper7 profile image MahaLakshmi Perumal ・1 min read

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
);
}
}

Discussion

pic
Editor guide
Collapse
thorstenhirsch profile image
Thorsten Hirsch

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.