Skip to content

Commit

Permalink
mint method issue still not fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonath-z committed Jul 2, 2022
1 parent da1a213 commit 05b91d3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
NEXT_PUBLIC_SUBGRAPH_NAME=
NEXT_PUBLIC_BACKEND_SERVICE_URL=https://ongama-nft-api.herokuapp.com/v1
NEXT_PUBLIC_MINT_CONTRACT_ADDRESS=0xB08347548b9DC9B1211D37913CE0f305FF477AcE
NEXT_PUBLIC_MINT_CONTRACT_ADDRESS=0xb08347548b9dc9b1211d37913ce0f305ff477ace
NEXT_PUBLIC_DEPLOYER_ADDRESS=0x8182677790c76d5a3CC8298d9643Cf8D4566C564
NEXT_PUBLIC_SUBGRAPH_GRAPHQL_ENDPOINT=https://api.thegraph.com/subgraphs/name/verdotte/ongama
NEXT_PUBLIC_CHAIN_WEB_SOCKET_URL=wss://ws-nd-801-935-229.p2pify.com/3b49b33557a73c552bae4a15c1843439
NEXT_PUBLIC_CHAIN_ID=80001
WEB3_NODE_RPC=https://matic-mumbai.chainstacklabs.com
NEXT_PUBLIC_WEB3_NODE_RPC=https://matic-mumbai.chainstacklabs.com
NEXT_PUBLIC_IPFS_AUTH=7100c075ab2d434bb74187580c4bb49b
NEXT_PUBLIC_STORAGE_FEE_RECEIVER_ADRESS=0xdBc8997C1273bD8bc5af15f16df26C4FA03c0852
NEXT_PUBLIC_STORAGE_FEE=0.0001
40 changes: 26 additions & 14 deletions components/CreateNftPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { backendApiService } from "@lib/services/BackendApiService";
import LocalStorage from "@lib/helper/LocalStorage";

const CreateNftPage = () => {
const [nftData, setNftData] = useState<NFT>({
const [nftData, setNftData] = useState({
category: "",
oldDropID: "",
dropId: 0,
Expand Down Expand Up @@ -73,7 +73,7 @@ const CreateNftPage = () => {
setNftData({
...nftData,
ownerAddress: LocalStorage.getItem("ongama_signer_address")!,
tokenUri: tokenUri,
tokenUri,
});
}, []);

Expand All @@ -93,7 +93,7 @@ const CreateNftPage = () => {
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
const { value, name } = event.target;
setNftData({ ...nftData, [name]: value });
setNftData((prevState) => ({ ...prevState, [name]: value }));
};

const onCancel = () => {
Expand All @@ -106,23 +106,30 @@ const CreateNftPage = () => {
...mintProcess,
uploadFileOnIpfsStatus: PENDING_STATUS,
});
console.log("input file", inputFiles);
const fileUrl = await saveFileWithIpfs(inputFiles);
console.log("file url", fileUrl);
if (fileUrl) {
setNftData({
...nftData,
fileSize: inputFiles[0].size,
fileType: inputFiles[0].type,
setNftData((prevState) => ({
...prevState,
url: fileUrl,
fileSize: inputFiles[0].size,
urlCompressed: fileUrl,
urlMedium: fileUrl,
urlThumbnail: fileUrl,
});
fileType: inputFiles[0].type,
}));
setMintProcess({
...mintProcess,
uploadFileOnIpfsStatus: SUCCED_STATUS,
});
} else {
setMintProcess({
...mintProcess,
uploadFileOnIpfsStatus: ERROR_STATUS,
});
return;
}
setMintProcess({ ...mintProcess, uploadFileOnIpfsStatus: ERROR_STATUS });
}
};

Expand All @@ -134,11 +141,11 @@ const CreateNftPage = () => {
});
const web3Service = new Web3Service();
const transaction = await web3Service.sendStorageFee();
setNftData({
...nftData,
setNftData((prevState) => ({
...prevState,
storageFeeTransaction: transaction.transactionHash,
storageFee: Number(process.env.STORAGE_FEE),
});
storageFee: Number(process.env.NEXT_PUBLIC_STORAGE_FEE),
}));
setMintProcess({
...mintProcess,
sendStorageFeeStatus: SUCCED_STATUS,
Expand All @@ -151,12 +158,17 @@ const CreateNftPage = () => {
}
};

// useEffect(() => {
// console.log("nft data", nftData);
// }, [nftData]);

const mintNft = async () => {
try {
setMintProcess({
...mintProcess,
mintNftStatus: PENDING_STATUS,
});
await uploadFileOnIPFS();
console.log("nft data on minting event", nftData);
// const uploadedonBd = await backendApiService.mintNft(nftData);
// console.log("nft uploaded on Bd", uploadedonBd);
Expand Down Expand Up @@ -184,7 +196,7 @@ const CreateNftPage = () => {
e.preventDefault();
setIsCreateNftProcessModal(!isCreateNftProcessModal);
try {
await uploadFileOnIPFS();
// await uploadFileOnIPFS();
// await sendStorageFee();
await mintNft();
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions lib/config/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const SUPPORTED_CHAINS: TNetworks = {
blockExplorer: "https://mumbai.polygonscan.com/",
nodeRPC: "https://matic-mumbai.chainstacklabs.com",
chainId: 80001,
mintContractAddress: "0xD96250D736642a487366170acd7823d8038Df212",
mintContractAddress: process.env.NEXT_PUBLIC_MINT_CONTRACT_ADDRESS!,
currency: "MATIC",
},
},
Expand All @@ -19,7 +19,7 @@ export const SUPPORTED_CHAINS: TNetworks = {
blockExplorer: "https://polygonscan.com/",
nodeRPC: "https://polygon-rpc.com/",
chainId: 137,
mintContractAddress: "0xCd494673999194365033D7A287af9f0a3b163874",
mintContractAddress: process.env.NEXT_PUBLIC_MINT_CONTRACT_ADDRESS!,
currency: "MATIC",
},
},
Expand Down
2 changes: 1 addition & 1 deletion lib/ipfsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ipfsClient = ipfsHttpClient({
port: 5001,
protocol: "https",
headers: {
authorization: process.env.IPFS_AUTH as string,
authorization: process.env.NEXT_PUBLIC_IPFS_AUTH as string,
},
});

Expand Down
22 changes: 13 additions & 9 deletions lib/web3/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Web3Service from "./service";
import LocalStorage from "@lib/helper/LocalStorage";
import { ethers } from "ethers";

const web3Instance = new Web3Service();

Expand Down Expand Up @@ -45,16 +44,21 @@ class Web3Actions {

//--------------------- this's the function that handles the mint nft from smart contract ------//
public async mintNft(tokenUri: string, address: string, price: number) {
const provider = web3Instance.provider;
const signer = await provider.getSigner(
LocalStorage.getItem("ongama_signer_address")
const formatedPrice = web3Instance.web3Instance.utils.toWei(
`${price}`,
"ether"
);
const formatedPrice = ethers.utils.parseUnits(price.toString(), "ether");
console.log("polygon signer", signer, "formated price ", formatedPrice);

await web3Instance
.contract("polygon", signer)
.mint(tokenUri, address, formatedPrice);
try {
const mintResult = await web3Instance
.contract()
.mint(tokenUri, address, formatedPrice, { from: address });

return mintResult;
} catch (err) {
console.log("error in minting =>", err);
return null;
}
}
}

Expand Down
17 changes: 7 additions & 10 deletions lib/web3/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ class Web3Service {
// web3Instance: Web3
}

public contract(chain: TChain = "polygon", signer: any) {
public contract(chain: TChain = "polygon") {
const network = this.getChainByName(chain);
console.log(
"nft contract address",
process.env.NEXT_PUBLIC_MINT_CONTRACT_ADDRESS!
);
console.log("mint contract address", network.mintContractAddress);
return new ethers.Contract(
network.mintContractAddress,
NFTABI.abi,
// this.provider
signer
this.provider.getSigner(LocalStorage.getItem("ongama_signer_address"))
);
}

Expand Down Expand Up @@ -102,8 +96,11 @@ class Web3Service {
const transaction = await this.web3Instance.eth.sendTransaction(
{
from: LocalStorage.getItem("ongama_signer_address")!,
to: process.env.STORAGE_FEE_RECEIVER_ADRESS!,
value: this.web3Instance.utils.toWei("0.001", "ether"),
to: process.env.NEXT_PUBLIC_STORAGE_FEE_RECEIVER_ADRESS!,
value: this.web3Instance.utils.toWei(
`${process.env.NEXT_PUBLIC_STORAGE_FEE}`,
"ether"
),
data: this.web3Instance.utils.toHex(""),
gas: 210000,
},
Expand Down

0 comments on commit 05b91d3

Please sign in to comment.