commit b744af9e90ebd2fa166d46209465fb24c1b77be7 Author: Vikas Singh Date: Tue Jul 13 12:59:27 2021 +0530 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..02aac3f --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `yarn start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.\ +You will also see any lint errors in the console. + +### `yarn test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `yarn build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `yarn eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `yarn build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js new file mode 100644 index 0000000..16a7ba5 --- /dev/null +++ b/migrations/1_initial_migration.js @@ -0,0 +1,5 @@ +const Migrations = artifacts.require("Migrations"); + +module.exports = function (deployer) { + deployer.deploy(Migrations); +}; diff --git a/migrations/2_contract_migration.js b/migrations/2_contract_migration.js new file mode 100644 index 0000000..000e32b --- /dev/null +++ b/migrations/2_contract_migration.js @@ -0,0 +1,17 @@ +const ImageContract = artifacts.require("ImageContract"); +const ImageSaleContract = artifacts.require("ImageSaleContract"); +const TokenContract = artifacts.require("TokenContract"); +const TokenSaleContract = artifacts.require("TokenSaleContract"); + +module.exports = async function (deployer) { + deployer.deploy(ImageContract).then(function() { + return deployer.deploy(ImageSaleContract, ImageContract.address); + }); + + deployer.deploy(TokenContract).then(function() { + var tokenPrice = 1000000000000000; // Token price is 0.001 Ether + var tokenContractAddress = TokenContract.address; + return deployer.deploy(TokenSaleContract, tokenContractAddress, tokenPrice); + }); + +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..cfb225c --- /dev/null +++ b/package.json @@ -0,0 +1,44 @@ +{ + "name": "vikas-nft", + "version": "0.1.0", + "private": true, + "dependencies": { + "@material-ui/core": "^4.11.4", + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "^11.1.0", + "@testing-library/user-event": "^12.1.10", + "@truffle/hdwallet-provider": "^1.4.1", + "bootstrap": "^5.0.1", + "react": "^17.0.2", + "react-dom": "^17.0.2", + "react-router-dom": "^5.2.0", + "react-scripts": "4.0.3", + "truffle": "^5.3.14", + "web-vitals": "^1.0.1", + "web3": "^1.3.6" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/public/ebizcoin.png b/public/ebizcoin.png new file mode 100644 index 0000000..d68d7b7 Binary files /dev/null and b/public/ebizcoin.png differ diff --git a/public/eth-logo.png b/public/eth-logo.png new file mode 100644 index 0000000..c8ac5ec Binary files /dev/null and b/public/eth-logo.png differ diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..5d7f527 --- /dev/null +++ b/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + NFT App + + + +
+ + + diff --git a/public/logo192.png b/public/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/public/logo192.png differ diff --git a/public/logo512.png b/public/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/public/logo512.png differ diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/public/profile.png b/public/profile.png new file mode 100644 index 0000000..97d4e47 Binary files /dev/null and b/public/profile.png differ diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/src/components/App.css b/src/components/App.css new file mode 100644 index 0000000..8ba1473 --- /dev/null +++ b/src/components/App.css @@ -0,0 +1,119 @@ +.token,.homeimage{ + object-fit: cover; + width: 100%; + height: 100%; + max-width: 100%; + max-height: 100%; +} +.iconimage{ + height: 40px; +} +.container{ + margin-top: 120px; + margin-bottom: 80px; +} +.navbar-brand{ + margin: 5px; +} +.profile{ + height: 40px; + width: 40px; + border-radius: 50%; +} +td { + white-space: normal !important; + word-wrap: break-word; +} +table { + table-layout: fixed; +} + +/* navbar-adj */ +.navbar-adj{box-shadow: 0 0px 20px -5px #77777777;height:80px} +.navbar-brand { + padding: 7px 15px; + font-size: 22px; + font-family: Avenir Next,Avenir,Avenir Next Local,sans-serif!important; + font-weight: 600; + /* border-radius: 20px 20px 0px 0px; */ + border-radius:20px 0px 20px 0px; + color: #3087dd !important; + background: #fff; + /* box-shadow: inset 0px -13px 20px -15px #3087dd; */ +} +/* nft-detail */ +.nft-detail-adj .table-adj tr th, .table-adj tr td {padding: 15px;} +.nft-detail-adj .table-adj tr th{background-color: #30dcdb33;width: 20%;} +.nft-detail-adj .table-adj tr{border: 1px solid #80808052;} +.nft-detail-adj .table-adj {margin:0 3em} + +/* home */ +/* .home-adj .wrapper,.form-wrapper {border: 1px solid #8080802b;height: fit-content;box-shadow:0 0px 20px -3px #77777721} +.home-adj .heading-container h1,.form-wrapper h3 {padding: 0.3em 1em 0.3em 0.3em;background: aliceblue;font-size: 36px;} */ +.home-adj,.explore-adj,.my-collect-adj,.mint-token-adj,.create-mint-adj,.nft-detail-adj{ + padding:5rem 1.5rem; + border: 1px solid #21252914; + margin-top: -20px; + border-radius: 5px; + background-color: #fff; + box-shadow: 0 1px 4px 0 rgb(0 0 0 / 14%); +} + +/* explore-adj */ +.explore-adj .card,.my-collect-adj .card{box-shadow:0 0px 20px -3px #77777777;} +.explore-adj .card:hover,.my-collect-adj .card:hover{box-shadow:0 0px 25px -2px #2062f077;} +.explore-adj a,.my-collect-adj a{text-decoration: none;color:#000} + + +/* .token {width: 100%;} */ + +/* footer */ +.footer-adj,.navbar-adj {background-color: #3087dd !important;color: #fff;} +.footer-adj p {margin-top: 1rem;margin-bottom: 1rem;} + +.max-250{ + height: 250px; + width: 100%; +} + +.max-300{ + height: 300px; + width: 100%; +} + +.text-title { + text-transform: uppercase; + color: rgb(255 255 255); + font-size: 14px; + font-weight: 600; + font-family: Avenir Next,Avenir,Avenir Next Local,sans-serif!important; + line-height: 1.5; + padding: 2px 8px; + background: #3031dc; + width: fit-content; + margin: 10px; + +} +.head-title { + display: inline-block; + background: #970097cf; + color: #fff; + border-radius: 5px; + padding: 5px 20px; +} + +.wrapper { + display: grid; +} +body { + background-color: #eee; +} +.btn-primary +{ + background-color:#00b9eb +} +.eth-class{ + height: 20px; + margin: 0px 5px; + padding-bottom: 5px; +} diff --git a/src/components/App.js b/src/components/App.js new file mode 100644 index 0000000..dde9410 --- /dev/null +++ b/src/components/App.js @@ -0,0 +1,82 @@ +import React, { Component } from 'react'; +import Web3 from 'web3'; +import './App.css'; + +import { + BrowserRouter as Router, + Switch, + Route +} from "react-router-dom"; + +import Home from './home/home'; +import Explore from './explore/explore'; +import Mint from './mint/mint'; +import NftDetail from './nft-detail/nft-detail'; +import MyCollection from './my-collection/my-collection'; +import Navbar from './navbar/navbar'; +import MintToken from './mint-token/mint-token'; + + +class App extends Component { + + async componentWillMount() { + await this.loadWeb3() + } + + async loadWeb3() { + if (window.ethereum) { + window.web3 = new Web3(window.ethereum) + window.loaded_web3 = true + await window.ethereum.enable() + } + else if (window.web3) { + window.web3 = new Web3(window.web3.currentProvider) + window.loaded_web3 = true + } + else { + window.alert('Non-Ethereum browser detected. You should consider trying MetaMask!') + } + } + + render() { + + return ( +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+

© Copyright Ebizon Pvt. Ltd.

+
+
+ ); + } +} + +export default App; \ No newline at end of file diff --git a/src/components/ebizcoin.png b/src/components/ebizcoin.png new file mode 100644 index 0000000..d68d7b7 Binary files /dev/null and b/src/components/ebizcoin.png differ diff --git a/src/components/eth-logo.png b/src/components/eth-logo.png new file mode 100644 index 0000000..c8ac5ec Binary files /dev/null and b/src/components/eth-logo.png differ diff --git a/src/components/explore/explore.js b/src/components/explore/explore.js new file mode 100644 index 0000000..4bc8945 --- /dev/null +++ b/src/components/explore/explore.js @@ -0,0 +1,179 @@ +import React, { Component } from 'react'; +import ImageContract from '../../abis/ImageContract.json'; +import TokenSaleContract from '../../abis/TokenSaleContract.json'; +import ImageSaleContract from '../../abis/ImageSaleContract.json'; + +import { + Link +} from "react-router-dom"; + +class Explore extends Component { + + render() { + + return ( +
+
+

Explore

+
+
+
+ {this.state.images.map((id, key) => { + return ( + + (this.state.approved[key] && (this.state.owners[key] !== this.state.account)) ? + ( +
+ +
{ + + }}> + +
+ token +
+
{"Name - " + this.state.imageData_name[key]}
+
{"Price - " + this.state.imageData_price[key]} + main +
+
{"Price - " + (this.state.imageData_price[key] * this.state.token_price)} + main +
+ +
+ +
+ ) : null + + ) + }) + } +
+
+
+ ) + + } + + constructor(props) { + super(props) + this.state = { + account: '', + contract: null, + sale_contract: null, + totalSupply: 0, + images: [], + owners: [], + imageData_name: [], + imageData_price: [], + selling_to: '', + selling_price: null, + token_sale_contract: null, + token_price: 0, + approved: [] + + } + } + + async componentWillMount() { + await this.loadBlockchainData() + await this.loadTokenSaleContract() + + } + + async loadBlockchainData() { + const web3 = window.web3 + // Load account + const accounts = await web3.eth.getAccounts() + this.setState({ account: accounts[0] }) + + const networkId = await web3.eth.net.getId() + const networkData = ImageContract.networks[networkId] + if (networkData) { + const abi = ImageContract.abi + const address = networkData.address + const contract = new web3.eth.Contract(abi, address) + // console.log(contract) + this.setState({ contract }) + const totalSupply = await contract.methods.totalSupply().call() + // console.log(totalSupply) + this.setState({ totalSupply }) + + + // Load NFTs + for (var i = 1; i <= totalSupply; i++) { + const id = await contract.methods.images(i - 1).call() + // console.log(id) + this.setState({ + images: [...this.state.images, id] + }) + } + // Load Owner + for (i = 1; i <= totalSupply; i++) { + const owner = await contract.methods.ownerOf(i - 1).call() + // console.log(owner) + this.setState({ + owners: [...this.state.owners, owner] + }) + } + // Load NFTs Data + for (i = 1; i <= totalSupply; i++) { + const metadata = await contract.methods.imageData(i - 1).call() + // console.log(metadata) + this.setState({ + imageData_name: [...this.state.imageData_name, metadata.name], + imageData_price: [...this.state.imageData_price, metadata.price] + }) + } + + } else { + window.alert('Smart contract not deployed to detected network.') + } + + const sale_networkData = ImageSaleContract.networks[networkId] + if (sale_networkData) { + const sale_abi = ImageSaleContract.abi + const sale_address = sale_networkData.address + const sale_contract = new web3.eth.Contract(sale_abi, sale_address) + // console.log(sale_contract) + this.setState({ sale_contract }) + + + for (i = 1; i <= this.state.totalSupply; i++) { + + var approv = await this.state.contract.methods.isApprovedOrOwner(this.state.sale_contract._address, (i - 1)).call(); + this.setState({ approved: [...this.state.approved, approv] }) + + // console.log(approv); + } + + } else { + window.alert('Smart contract not deployed to detected network.') + } + } + + async loadTokenSaleContract() { + const web3 = window.web3 + + const networkId = await web3.eth.net.getId() + const networkData = TokenSaleContract.networks[networkId] + if (networkData) { + const abi = TokenSaleContract.abi + const address = networkData.address + const token_sale_contract = new web3.eth.Contract(abi, address) + this.setState({ token_sale_contract }) + // console.log(token_sale_contract) + + var token_price = await this.state.token_sale_contract.methods.tokenPrice().call(); + this.setState({ token_price: web3.utils.fromWei(token_price, "ether") }) + + } else { + window.alert('Smart contract not deployed to detected network.') + } + } + +} +export default Explore; \ No newline at end of file diff --git a/src/components/home/home.js b/src/components/home/home.js new file mode 100644 index 0000000..10f03e2 --- /dev/null +++ b/src/components/home/home.js @@ -0,0 +1,49 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; + +const Home = () => { + window.loaded_web3 = false; + + const history = useHistory(); + const handleClick1 = () => { + history.push('/explore'); + } + const handleClick2 = () => { + history.push('/mint'); + } + + return ( + +
+
+

Home

+
+
+
+
+
+ home +
+
Featured NFT
+
+
+ +
+
+

Welcome to NFT Marketplace

+

+ Here you can buy and sell NFTs. As word spreads about the rise of Non-Fungible Tokens (NFTs), we’re fielding more and more questions from artists and creators looking to sell their work on the blockchain. Here’s how to turn your art into NFTs and list them for sale. +

+
+
+ + +
+
+ +
+
+ ) +}; + +export default Home; diff --git a/src/components/mint-token/mint-token.js b/src/components/mint-token/mint-token.js new file mode 100644 index 0000000..3aff0ee --- /dev/null +++ b/src/components/mint-token/mint-token.js @@ -0,0 +1,110 @@ +import React, { Component } from 'react'; +import TokenSaleContract from '../../abis/TokenSaleContract.json'; + +class MintToken extends Component { + + render() { + + return ( +
+
+

Get Token

+
+
+
+
+
+

Buy Ebizon Tokens (ETK)

+
{"Tokens Available - " + this.state.tokens_available}
+
{"Token Price - " + this.state.token_price} + main +
+
{ + event.preventDefault() + this.buyToken(); + }}> + this.setState({ token_no: event.target.value })} + /> + +
+
+
+
+
+
+ ) + + } + + constructor(props) { + super(props) + this.state = { + account: '', + token_sale_contract: null, + tokens_available: '', + token_price: 0, + token_no: 0 + } + } + + async componentWillMount() { + await this.loadBlockchainData() + } + + async loadBlockchainData() { + const web3 = window.web3 + // Load account + const accounts = await web3.eth.getAccounts() + this.setState({ account: accounts[0] }) + + const networkId = await web3.eth.net.getId() + const networkData = TokenSaleContract.networks[networkId] + if (networkData) { + const abi = TokenSaleContract.abi + const address = networkData.address + const token_sale_contract = new web3.eth.Contract(abi, address) + this.setState({ token_sale_contract }) + console.log(token_sale_contract) + + var tokens_available = await this.state.token_sale_contract.methods.balanceTokens().call(); + this.setState({ tokens_available: web3.utils.fromWei(tokens_available, "ether") }) + + var token_price = await this.state.token_sale_contract.methods.tokenPrice().call(); + this.setState({ token_price: web3.utils.fromWei(token_price, "ether") }) + + } else { + window.alert('Smart contract not deployed to detected network.') + } + } + + + buyToken = () => { + + var buy_price = this.state.token_price * this.state.token_no; + + const web3 = window.web3 + web3.eth.sendTransaction({ to: "0x0000ADb55545be52c7DB7983cC95d177F29D3C5D", from: this.state.account, value: web3.utils.toWei(buy_price.toString(), "ether") }) + .once('receipt', (receipt) => { + console.log("ether transfered") + + this.state.token_sale_contract.methods.buyTokens( + web3.utils.toWei(this.state.token_no, "ether") + ).send({ from: this.state.account }) + .once('receipt', (receipt) => { + console.log("tokens bought"); + }); + }) + + + } + +} +export default MintToken; \ No newline at end of file diff --git a/src/components/mint/mint.js b/src/components/mint/mint.js new file mode 100644 index 0000000..bf34626 --- /dev/null +++ b/src/components/mint/mint.js @@ -0,0 +1,203 @@ +import React, { Component } from 'react'; +import ImageContract from '../../abis/ImageContract.json'; +import ImageSaleContract from '../../abis/ImageSaleContract.json'; + +class Mint extends Component { + + + render() { + + return ( +
+
+

Create Token

+
+
+
+
+
+

Create Image NFT

+
{ + event.preventDefault() + this.mintImage(); + }}> +
+ this.setState({ new_image: event.target.files[0] })} + /> +
+
+ this.setState({ new_name: event.target.value })} + /> +
+
+ this.setState({ new_url: event.target.value })} + /> +
+
+ this.setState({ new_price: event.target.value })} + /> +
+
+