0

Hey everyone

I'm new to NFT development. I developed an ERC-721 token used for property ownership and I deployed and minted a token both on Anvil and sepolia. I can import the token on metamask but its image is not showing up.

please help me know what is the problem and how can i solve it

the contract on sepolia: https://sepolia.etherscan.io/address/0x609074096e1f172ced194639c6cf6bca731495d2

the image IPFS CID: ipfs://QmVQfqv5YNXL73ypG125BBsooWRiVubF5nm2g9tRtPtyx8

And the contract code:

pragma solidity ^0.8.18;

import {ERC721} from "@OpenZeppelin/contracts/token/ERC721/ERC721.sol";
import {Base64} from "@OpenZeppelin/contracts/utils/Base64.sol";
import {Strings} from "@OpenZeppelin/contracts/utils/Strings.sol";

contract EProp is ERC721 {
    
    string private s_imageUri;
    address private immutable i_owner;
    uint256 private s_tokenCounter;

    mapping(uint256 => PropSpec) public tokenIdtoSpec;

    struct PropSpec {
        uint256 height;
        uint256 width;
        uint256 x;
        uint256 y;
        //PropType propType;
    }

    constructor(string memory imageUri) ERC721("eProp", "EPR") {
        i_owner = msg.sender;
        s_imageUri = imageUri;
        //s_imageUri:"ipfs://QmVQfqv5YNXL73ypG125BBsooWRiVubF5nm2g9tRtPtyx8"
    }

    function mintProp(
        address propOwner,
        uint256 height,
        uint256 width,
        uint256 x,
        uint256 y
    ) public {
        _safeMint(propOwner, s_tokenCounter);
        PropSpec memory propSpec = PropSpec(height, width, x, y);
        tokenIdtoSpec[s_tokenCounter] = propSpec;
        s_tokenCounter++;
    }

    function _baseURI() internal pure override returns (string memory) {
        return "data:application/json;base64,";
    }

    function tokenURI(
        uint256 tokenId
    ) public view override returns (string memory) {
        string memory height = Strings.toString(tokenIdtoSpec[tokenId].height);
        string memory width = Strings.toString(tokenIdtoSpec[tokenId].width);
        string memory x = Strings.toString(tokenIdtoSpec[tokenId].x);
        string memory y = Strings.toString(tokenIdtoSpec[tokenId].y);
        return
            string(
                abi.encodePacked(
                    _baseURI(),
                    Base64.encode(
                        bytes(
                            abi.encodePacked(
                                '{"name":"',
                                name(),
                                '","description":"EProp is a decentralized property ownership system.","attributes":[{"height":"',
                                height,
                                '","width":"',
                                width,
                                '","x":"',
                                x,
                                '","y":"',
                                y,
                                '"}],"image":"',
                                s_imageUri,
                                '"}'
                            )
                        )
                    )
                )
            );
    }
}

1 Answer 1

0

I think that is from the invalid image URL. https://ipfs.io/ipfs/QmVQfqv5YNXL73ypG125BBsooWRiVubF5nm2g9tRtPtyx8

That is the correct format and if you click the link you should see the image clearly.

Thanks.

1
  • Hey there, thanks a lot for the reply,I fixed the contract issue by adding my file to Pinata, the problem was that metamask couldn't get the svg file while my local IPFS node was off and I didn't know that but now it's done
    – emtothed
    Sep 25, 2023 at 11:23

Your Answer

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

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