I’m working on a project to mint NFTs across different blockchains using Chainlink’s CCIP. The tutorial I’m following puts the IPFS NFT Metadata URL directly in the destination chain’s MyNFT contract. But I want users to input the URL on the source chain and send it to the destination chain for minting.
I’ve tried to do this but it’s not working as expected. After sending the transaction from the source chain with the URL, the CCIP transaction goes through fine. However, I can’t find the minted NFT on the destination chain.
Here’s what my code looks like on the source chain:
function mint(
uint64 _destChainId,
address _to,
address _tokenAddr,
uint256 _tokenAmount,
string memory _nftMetadata
) external onlyAllowedChain(_destChainId) returns (bytes32 msgId) {
Client.EVMTokenAmount[] memory tokens = new Client.EVMTokenAmount[](1);
tokens[0] = Client.EVMTokenAmount(_tokenAddr, _tokenAmount);
Client.EVM2AnyMessage memory ccipMsg = Client.EVM2AnyMessage({
receiver: abi.encode(_to),
data: abi.encodeWithSignature("mint(address, string)", msg.sender, _nftMetadata),
tokenAmounts: tokens,
extraArgs: "",
feeToken: address(linkToken)
});
uint256 ccipFee = router.getFee(_destChainId, ccipMsg);
require(linkToken.balanceOf(address(this)) >= ccipFee, "Not enough LINK");
linkToken.approve(address(router), ccipFee);
IERC20(_tokenAddr).approve(address(router), _tokenAmount);
msgId = router.ccipSend(_destChainId, ccipMsg);
emit TokensSent(msgId, _destChainId, _to, _tokenAddr, _tokenAmount, ccipFee);
}
And here’s the mint function on the destination chain:
function mint(address to, string memory TOKEN_URI) public {
_safeMint(to, tokenId);
_setTokenURI(tokenId, TOKEN_URI);
unchecked {
tokenId++;
}
}
What am I doing wrong? How can I fix this to properly transfer and use the metadata URL?