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,
'"}'
)
)
)
)
);
}
}