const nftAddress = "0x3e0f64d801823706f29686eeca0aac521e77674e"; const NFTManagerABI = [ { inputs: [], stateMutability: "payable", type: "constructor", }, { anonymous: false, inputs: [ { indexed: false, internalType: "address", name: "nftContract", type: "address", }, { indexed: false, internalType: "uint256", name: "tokenId", type: "uint256", }, { indexed: false, internalType: "address", name: "storeAddress", type: "address", }, { indexed: false, internalType: "address", name: "owner", type: "address", }, { indexed: false, internalType: "uint256", name: "amount", type: "uint256", }, { indexed: false, internalType: "string", name: "store", type: "string", }, ], name: "NFTListed", type: "event", }, { anonymous: false, inputs: [ { indexed: false, internalType: "address", name: "nftContract", type: "address", }, { indexed: false, internalType: "uint256", name: "tokenId", type: "uint256", }, { indexed: false, internalType: "address", name: "storeAddress", type: "address", }, { indexed: false, internalType: "address", name: "owner", type: "address", }, { indexed: false, internalType: "uint256", name: "amount", type: "uint256", }, { indexed: false, internalType: "string", name: "store", type: "string", }, ], name: "NFTSold", type: "event", }, { inputs: [ { internalType: "address", name: "_nftContract", type: "address", }, { internalType: "uint256", name: "_tokenId", type: "uint256", }, { internalType: "uint256", name: "_amount", type: "uint256", }, ], name: "approveTransaction", outputs: [], stateMutability: "payable", type: "function", }, { inputs: [], name: "getBalance", outputs: [ { internalType: "uint256", name: "", type: "uint256", }, ], stateMutability: "view", type: "function", }, { inputs: [], name: "getMyActiveTransactions", outputs: [ { components: [ { internalType: "address", name: "nftContract", type: "address", }, { internalType: "uint256", name: "tokenId", type: "uint256", }, { internalType: "address payable", name: "storeAddress", type: "address", }, { internalType: "address payable", name: "owner", type: "address", }, { internalType: "uint256", name: "amount", type: "uint256", }, { internalType: "string", name: "store", type: "string", }, ], internalType: "struct NFTManager.NFT[]", name: "", type: "tuple[]", }, ], stateMutability: "view", type: "function", }, { inputs: [], name: "getStoreActiveTransactions", outputs: [ { components: [ { internalType: "address", name: "nftContract", type: "address", }, { internalType: "uint256", name: "tokenId", type: "uint256", }, { internalType: "address payable", name: "storeAddress", type: "address", }, { internalType: "address payable", name: "owner", type: "address", }, { internalType: "uint256", name: "amount", type: "uint256", }, { internalType: "string", name: "store", type: "string", }, ], internalType: "struct NFTManager.NFT[]", name: "", type: "tuple[]", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "address", name: "_nftContract", type: "address", }, { internalType: "uint256", name: "_tokenId", type: "uint256", }, { internalType: "uint256", name: "_amount", type: "uint256", }, { internalType: "address payable", name: "_storeAddress", type: "address", }, { internalType: "string", name: "store", type: "string", }, ], name: "initTransaction", outputs: [], stateMutability: "payable", type: "function", }, ]; const walleyAddress = "0x2ebb88cd2a775308636afad718800bbb82f19137"; const WalleyABI = [ { inputs: [ { internalType: "address", name: "_marketplaceContract", type: "address", }, ], stateMutability: "nonpayable", type: "constructor", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address", }, { indexed: true, internalType: "address", name: "approved", type: "address", }, { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "Approval", type: "event", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address", }, { indexed: true, internalType: "address", name: "operator", type: "address", }, { indexed: false, internalType: "bool", name: "approved", type: "bool", }, ], name: "ApprovalForAll", type: "event", }, { anonymous: false, inputs: [ { indexed: false, internalType: "uint256", name: "_fromTokenId", type: "uint256", }, { indexed: false, internalType: "uint256", name: "_toTokenId", type: "uint256", }, ], name: "BatchMetadataUpdate", type: "event", }, { anonymous: false, inputs: [ { indexed: false, internalType: "uint256", name: "_tokenId", type: "uint256", }, ], name: "MetadataUpdate", type: "event", }, { anonymous: false, inputs: [ { indexed: false, internalType: "uint256", name: "", type: "uint256", }, ], name: "NFTMinted", type: "event", }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "from", type: "address", }, { indexed: true, internalType: "address", name: "to", type: "address", }, { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "Transfer", type: "event", }, { inputs: [ { internalType: "address", name: "to", type: "address", }, { internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "approve", outputs: [], stateMutability: "nonpayable", type: "function", }, { inputs: [ { internalType: "address", name: "owner", type: "address", }, ], name: "balanceOf", outputs: [ { internalType: "uint256", name: "", type: "uint256", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "getApproved", outputs: [ { internalType: "address", name: "", type: "address", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "address", name: "owner", type: "address", }, { internalType: "address", name: "operator", type: "address", }, ], name: "isApprovedForAll", outputs: [ { internalType: "bool", name: "", type: "bool", }, ], stateMutability: "view", type: "function", }, { inputs: [], name: "mint", outputs: [ { internalType: "uint256", name: "", type: "uint256", }, ], stateMutability: "nonpayable", type: "function", }, { inputs: [], name: "name", outputs: [ { internalType: "string", name: "", type: "string", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "ownerOf", outputs: [ { internalType: "address", name: "", type: "address", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "address", name: "from", type: "address", }, { internalType: "address", name: "to", type: "address", }, { internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "safeTransferFrom", outputs: [], stateMutability: "nonpayable", type: "function", }, { inputs: [ { internalType: "address", name: "from", type: "address", }, { internalType: "address", name: "to", type: "address", }, { internalType: "uint256", name: "tokenId", type: "uint256", }, { internalType: "bytes", name: "data", type: "bytes", }, ], name: "safeTransferFrom", outputs: [], stateMutability: "nonpayable", type: "function", }, { inputs: [ { internalType: "address", name: "operator", type: "address", }, { internalType: "bool", name: "approved", type: "bool", }, ], name: "setApprovalForAll", outputs: [], stateMutability: "nonpayable", type: "function", }, { inputs: [ { internalType: "bytes4", name: "interfaceId", type: "bytes4", }, ], name: "supportsInterface", outputs: [ { internalType: "bool", name: "", type: "bool", }, ], stateMutability: "view", type: "function", }, { inputs: [], name: "symbol", outputs: [ { internalType: "string", name: "", type: "string", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "tokenURI", outputs: [ { internalType: "string", name: "", type: "string", }, ], stateMutability: "view", type: "function", }, { inputs: [ { internalType: "address", name: "from", type: "address", }, { internalType: "address", name: "to", type: "address", }, { internalType: "uint256", name: "tokenId", type: "uint256", }, ], name: "transferFrom", outputs: [], stateMutability: "nonpayable", type: "function", }, ]; State.init({ chainId: undefined, balance: 0, transfers: [], }); const sender = Ethers.send("eth_requestAccounts", [])[0]; if (!sender) return <Web3Connect connectLabel="Connect with Web3" />; if (state.chainId === undefined && ethers !== undefined && sender) { Ethers.provider() .getNetwork() .then((chainIdData) => { if (chainIdData?.chainId) { State.update({ chainId: chainIdData.chainId }); } }); Ethers.provider() .getBalance(sender) .then((balance) => { State.update({ balance: Big(balance).div(Big(10).pow(18)).toFixed(2) }); }); console.log(sender); } if (state.chainId !== undefined && state.chainId !== 11155111) { return <p>Switch to Ethereum Sepolia</p>; } console.log(NFTManagerABI); const nftIface = new ethers.utils.Interface(NFTManagerABI); console.log("hehe"); const nftContract = new ethers.Contract( nftAddress, NFTManagerABI, Ethers.provider().getSigner() ); const walleyIface = new ethers.utils.Interface(WalleyABI); const walleyContract = new ethers.Contract( walleyAddress, WalleyABI, Ethers.provider().getSigner() ); const mint = () => { walleyContract .mint({ from: sender }) .then((tokenId) => console.log(tokenId)) .then((t) => console.log(t)) .catch((err) => console.log(err)); }; const initTransaction = () => { // walleyContract // .mint({ from: sender }) // .then((t) => { // console.log("minted"); // List the NFT console.log(ethers.utils.toWei("0.1", "ether")); nftContract .initTransaction( walleyAddress, "1", ethers.utils.toWei("0.1", "ether"), "0xF0DB85E02DBC2d2c9b86dFC245cd9C2CAF9a901B", "Test", { from: sender, value: "0.1 ether" } ) .then(() => console.log("done")) .catch((err) => console.log("err")); }; // .catch((err) => console.log("hhhh")); const createTransfer = () => { if (contract) { console.log("hhh"); contract .createTransfer(1000, "0xF0DB85E02DBC2d2c9b86dFC245cd9C2CAF9a901B") .then(() => { console.log("hello"); }) .catch((err) => console.log(err)); } }; const getTransfers = () => { if (state.transfers.length === 0) { console.log("hhh"); contract .getTransfers() .then((transfers) => { const tmp = [...state.transfers]; transfers.map((transfer) => { console.log(transfer); tmp.push({ id: Big(transfer[0]).toFixed(0), amount: Big(transfer[1]).div(Big(10).pow(18)).toFixed(20), to: transfer[2], sent: transfer[3], approver: transfer[4], }); }); State.update({ transfers: tmp }); console.log(transfers); }) .then(() => { console.log(state.transfers); }) .catch((err) => { console.log(err); }); } }; const approveTransfer = (id) => { console.log(id); contract.approveTransfer(id).send({ from: sender }); }; return ( <> <p>{state.chainId}</p> <p>{state.balance}</p> <button onClick={mint}>Mint</button> <button onClick={initTransaction}>init</button> </> );