Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushMP committed Jun 7, 2024
1 parent 5176c6b commit 89bb919
Show file tree
Hide file tree
Showing 20 changed files with 27,824 additions and 10,002 deletions.
22,985 changes: 13,088 additions & 9,897 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@truffle/hdwallet-provider": "^1.7.0",
"ethers": "^6.13.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
"react-router-dom": "^6.23.1",
"react-scripts": "^3.0.1",
"web-vitals": "^2.1.4",
"web3": "^4.9.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

44 changes: 25 additions & 19 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import logo from './logo.svg';
import './App.css';
import React from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import Layout from './pages/Layout';
import UserAccountPage from './pages/UserAccountPage';
import LoginPage from './pages/LoginPage';
import MyNFTsPage from './pages/MyNFTsPage';
import MySoldNFTsPage from './pages/MySoldNFTsPage';
import MarketplacePage from './pages/MarketplacePage';
import CreateNFTPage from './pages/CreateNFTPage';
import NoPage from './pages/NoPage';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<UserAccountPage />} /> {/* Assuming you want UserAccountPage as the home page */}
<Route path="login" element={<LoginPage />} />
<Route path="account" element={<UserAccountPage />} />
<Route path="mynfts" element={<MyNFTsPage />} />
<Route path="mysoldnfts" element={<MySoldNFTsPage />} />
<Route path="marketplace" element={<MarketplacePage />} />
<Route path="createnft" element={<CreateNFTPage />} />
<Route path="*" element={<NoPage />} />
</Route>
</Routes>
</BrowserRouter>
);
}

export default App;
export default App;
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

72 changes: 72 additions & 0 deletions src/Components/EthereumInteraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { useState, useEffect } from 'react';
import Web3 from 'web3';
import NFTContract from "../Contracts/NFT.json"; // Import your NFT contract ABI

function EthereumInteraction() {
const [web3, setWeb3] = useState(null);
const [nftContract, setNFTContract] = useState(null);
const [accounts, setAccounts] = useState([]);
const [nftOwner, setNFTOwner] = useState('');

useEffect(() => {
async function connectToMetaMask() {
if (window.ethereum) {
try {
// Initialize Web3
const web3Instance = new Web3(window.ethereum);
setWeb3(web3Instance);

// Request account access
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
setAccounts(accounts);

// Initialize NFT contract
const networkId = await web3Instance.eth.net.getId();
const deployedNetwork = NFTContract.networks[networkId];
const contract = new web3Instance.eth.Contract(
NFTContract.abi,
deployedNetwork && deployedNetwork.address
);
setNFTContract(contract);

// Get owner of NFT
if (contract) {
const owner = await contract.methods.owner().call();
setNFTOwner(owner);
}
} catch (error) {
console.error('Error connecting to MetaMask:', error);
}
} else {
console.error('MetaMask is not installed');
}
}
connectToMetaMask();
}, []);

return (
<div>
<h2>Ethereum Interaction</h2>
{web3 ? (
<p>Connected to Ethereum network</p>
) : (
<p>Not connected to Ethereum network</p>
)}

{accounts.length > 0 ? (
<p>Connected account: {accounts[0]}</p>
) : (
<p>No accounts connected</p>
)}

{nftContract && (
<div>
<p>NFT Contract Address: {nftContract._address}</p>
<p>Owner of NFT Contract: {nftOwner}</p>
</div>
)}
</div>
);
}

export default EthereumInteraction;
Loading

0 comments on commit 89bb919

Please sign in to comment.