Skip to content

Commit

Permalink
make destination contract receive both token and data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginowine committed Dec 6, 2023
1 parent 44235f3 commit e7e9cad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions contracts/CrossNftDestinationMinter.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {MyNFT} from "./MyNFT.sol";

contract CrossNftDestinationMinter is CCIPReceiver {
MyNFT nft;
contract CrossNftDestinationMinter is CCIPReceiver, OwnerIsCreator{
MyNFT public nft;
uint256 price;

event MintCallSuccessfull();

constructor(address router, address nftAddress) CCIPReceiver(router) {
nft = MyNFT(nftAddress);
constructor(address router, uint256 _price) CCIPReceiver(router) {
nft = new MyNFT();
price = _price;
}

function _ccipReceive(
Client.Any2EVMMessage memory message
) internal override {
require(message.destTokenAmounts[0].amount >= price, "Not enough CCIP-BnM for mint");
(bool success, ) = address(nft).call(message.data);
require(success);
emit MintCallSuccessfull();
Expand Down
2 changes: 1 addition & 1 deletion contracts/CrossNftSourceMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract CrossNftSourceMinter is OwnerIsCreator{
// Build the CCIP Message
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(_receiver),
data: abi.encodeWithSignature("mint(address, _metadataURL)", msg.sender),
data: abi.encodeWithSignature("mint(address, string)", msg.sender, _metadataURL),
tokenAmounts: tokenAmounts,
extraArgs: Client._argsToBytes(
Client.EVMExtraArgsV1({gasLimit: 200_000, strict: false})
Expand Down
6 changes: 3 additions & 3 deletions contracts/MyNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721URIStorage, Ownable {
string constant TOKEN_URI =
"https://ipfs.io/ipfs/QmYuKY45Aq87LeL1R5dhb1hqHLp6ZFbJaCP8jxqKM1MX6y/babe_ruth_1.json";
// string constant TOKEN_URI =
// "https://ipfs.io/ipfs/QmYuKY45Aq87LeL1R5dhb1hqHLp6ZFbJaCP8jxqKM1MX6y/babe_ruth_1.json";
uint256 internal tokenId;

constructor(address initialOwner) ERC721("MyNFT", "MNFT") Ownable(initialOwner){}

function mint(address to) public onlyOwner {
function mint(address to, string memory TOKEN_URI) public onlyOwner {
_safeMint(to, tokenId);
_setTokenURI(tokenId, TOKEN_URI);
unchecked {
Expand Down

0 comments on commit e7e9cad

Please sign in to comment.