I have a very basic but functional smart contract which stores an image URL (and some other fields) for front-end use. However, while it works with shortened image URLs, most URLs are too long, causing the gas costs to skyrocket beyond the block gas limit.

Is there a more efficient way to store the URLs, or would I need to automatically shorten them somehow before sending them to the back-end?

For some context, here is my contract (As mentioned, very basic):

contract Advertisement {
    string private image_url = "https://via.placeholder.com/350";
    string private text = "Placeholder text";
    uint private price = 0; // First user can upload their image for free (+gas);

    function updateAdvertisement(string memory new_image, string memory new_text) public payable {
        require(msg.value > price, "Payment must be greater than the listed price");
        image_url = new_image;
        text = new_text;
        price = msg.value;

    function getAdvertisement() public view returns(string memory, string memory, uint) {
        return (image_url, text, price);

1 Answer 1


If you would like to store the url data decentralized then IPFS is a good way to go.

If you just want to use the url to display something and use it off-chain (backend). Instead of returns the real url, you can returns the id of the url, the backend can look from db for the url based on that id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.