Skip to content

Commit

Permalink
Merge pull request #10 from fabriziogianni7/ccip_integration
Browse files Browse the repository at this point in the history
Ccip integration with frontend
  • Loading branch information
ntefa authored Nov 18, 2023
2 parents 9fbe705 + fe414c9 commit a8d3aad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/hardhat/contracts/BuyerNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract BuyerNFT is ERC721URIStorage, Ownable {
function tokenIDs(address speaker) external view returns (uint256[] memory) {
return _tokenIDs[speaker];
}
function getNFTMetadata(uint256 tokenId)
function getNFTMetadata(uint256 tknId)
public
view
returns (
Expand All @@ -66,7 +66,7 @@ contract BuyerNFT is ERC721URIStorage, Ownable {
string memory script
)
{
NFTMetadata storage metadata = nftMetadata[tokenId];
NFTMetadata storage metadata = nftMetadata[tknId];
return (
metadata.cid,
metadata.speakerAddress,
Expand Down
8 changes: 4 additions & 4 deletions packages/hardhat/contracts/ccip_buyer/sourceMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ contract SourceMinter is Withdraw {
function mint (
uint64 destinationChainSelector,
address receiver,
PayFeesIn payFeesIn,
PayFeesIn payFeesIn,
string memory cID,
string memory name,
string memory script
string memory _audioScript,
uint256 _audioPrice
) external {
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(receiver),
data: abi.encodeWithSignature("mint(address,string,string,string)",msg.sender,cID,name,script),
data: abi.encodeWithSignature("mint(address,string,string,uint256)",msg.sender,cID,_audioScript,_audioPrice),
tokenAmounts: new Client.EVMTokenAmount[](0),
extraArgs: Client._argsToBytes(
Client.EVMExtraArgsV1({gasLimit: 1000000, strict: false})
Expand Down
25 changes: 17 additions & 8 deletions packages/nextjs/components/record/Recorder.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useState } from "react";
import lighthouse from "@lighthouse-web3/sdk";
import { polygonMumbai } from "@wagmi/core/chains";
import { LoaderIcon } from "react-hot-toast";
import { useAccount, useContractWrite } from "wagmi";
import { useAccount, useContractWrite, useNetwork } from "wagmi";
import { ContractsAndAbis } from "~~/hooks/dub3/utils";
import { notification } from "~~/utils/scaffold-eth";

Expand All @@ -12,14 +13,19 @@ export const Recorder = () => {
const [price, setPrice] = useState("");
const [cid, setCid] = useState("");
const { address: to, isDisconnected } = useAccount();

const { chain } = useNetwork();
const destinationChainSelector = "12532609583862916517";
const receiver = "0xF0228036FC21aD442250d4c887F492c50b5A3A37";
const payFeesIn = 1;
const SAMPLE_TEXT =
" Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace the future today.";

// const { ...writeHook } = useDub3Contract({ contractName: "SpeakerNFT", functionName: "mint" });
"Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace the future today.";
console.log(chain);
const { data, isSuccess, write } = useContractWrite({
address: ContractsAndAbis.SpeakerNFT.address,
abi: ContractsAndAbis.SpeakerNFT.abi,
address:
chain?.id == polygonMumbai.id ? ContractsAndAbis.SpeakerNFT.address : ContractsAndAbis.SourceMinter.address,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
abi: chain?.id == polygonMumbai.id ? ContractsAndAbis.SpeakerNFT.abi : ContractsAndAbis.SourceMinter.abi,
functionName: "mint",
});

Expand Down Expand Up @@ -65,7 +71,10 @@ export const Recorder = () => {
}
console.log(ContractsAndAbis.SpeakerNFT.abi);
write({
args: [to, cid, SAMPLE_TEXT, 0], // to, cid,audioscript,audioprice
args:
chain?.id == polygonMumbai.id
? [to, cid, SAMPLE_TEXT, 0]
: [destinationChainSelector, receiver, payFeesIn, cid, SAMPLE_TEXT, 0], // to, cid,audioscript,audioprice
});
};
return (
Expand Down
13 changes: 8 additions & 5 deletions packages/nextjs/hooks/dub3/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { abi } from "./SpeakerNFTAbi";
import { abi as buyerAbi } from "./BuyerNFTABI";
import { abi as speakerAbi } from "./SpeakerNFTAbi";
import { abi as destinationMinterABI } from "./destinationMinterABI";
import { abi as sourceMinterAbi } from "./sourceMinterABI";

export const ContractsAndAbis = {
SpeakerNFT: {
address: "0xB31B82CDF32ce766E7acB943565347383Ac9ec26",
abi: abi,
abi: speakerAbi,
},
BuyerNFT: {
address: "0x59087174Dd6F511C73e62618DaeE710F2db0819F",
abi: abi,
abi: buyerAbi,
},
SourceMinter: {
address: "0x7e28Bca799F90AB6e8264E93B123cE9990987567",
abi: abi,
abi: sourceMinterAbi,
},
DestinationMinter: {
address: "0xF0228036FC21aD442250d4c887F492c50b5A3A37",
abi: abi,
abi: destinationMinterABI,
},
};

Expand Down

0 comments on commit a8d3aad

Please sign in to comment.