Skip to content

Commit

Permalink
fixes transaction error
Browse files Browse the repository at this point in the history
  • Loading branch information
jenil04 committed Sep 1, 2019
1 parent 9c96f1b commit 0129c43
Show file tree
Hide file tree
Showing 10 changed files with 769 additions and 1,313 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title> Inro to Web3.js </title>
<title> Intro to Web3.js </title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
39 changes: 11 additions & 28 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import React, { Component } from "react";
import web3 from "./web3";
import auction from "./auction";

// Styling
import { Layout } from "./Layout";
import "./App.css";
import { Button } from "react-bootstrap";
import Typist from 'react-typist';

class App extends Component {
constructor(props) {
super(props);

this.state = {
state = {
bids: [],
bidders: [],
seller: "",
Expand All @@ -19,16 +17,14 @@ class App extends Component {
value: "",
message: ""
};
}


async componentDidMount() {
const bids = await auction.methods.getBids().call();
const seller = await auction.methods.seller().call();
const highestBidder = await auction.methods.getHighestBidder().call();
const bidders = await auction.methods.getBidders().call();
const auctionValue = await web3.eth.getBalance(
"0x8B167cf1754005F502774Ffe63857C8C66B5B9f1"
);
const auctionValue = await web3.eth.getBalance(auction.options.address);

this.setState({
bids,
Expand All @@ -39,17 +35,17 @@ class App extends Component {
});
}

onEnter = async event => {
onSubmit = async (event) => {
event.preventDefault();
const accounts = await web3.eth.getAccounts();

this.setState({
message: "Processing..."
message: "Confirming transaction..."
});

await auction.methods.submitBid().send({
from: accounts[0],
valuecd: web3.utils.toWei(this.state.value, "ether")
value: web3.utils.toWei(this.state.value, "ether")
});

this.setState({
Expand All @@ -60,17 +56,13 @@ class App extends Component {
onClick = async () => {
const accounts = await web3.eth.getAccounts();

this.setState({
message: "Picking the highest bidder..."
});
this.setState({ message: 'Awaiting transaction success...' })

await auction.methods.determineWinner().send({
from: accounts[0]
});

this.setState({
message: "Sold, to the highest bidder!"
});
this.setState({ message: 'A winner has been picked!' });
};

render() {
Expand All @@ -79,18 +71,9 @@ class App extends Component {
<Layout>
<div className="text-center">
<Typist> <span className="text-white justify-center text-center" > Decentralized Auction on Ethereum.</span></Typist>
<br />
<Typist>
<span className="w-full block text-white text-5xl font-fancy font-bold text-center justify-center mb-8">
There are currently {this.state.bidders.length} people entered,
competing to bid {" "}
{web3.utils.fromWei(this.state.auctionValue, "ether")} ether.{" "}
</span>
</Typist>

<hr/>

<form onSubmit={this.onEnter} >
<form onSubmit={this.onSubmit} >
<h4 className="text-white justify-center" >Join the Auction: </h4>
<br />
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ let abi = [
"type": "function"
}
];
let address = "0x8B167cf1754005F502774Ffe63857C8C66B5B9f1";
let address = "0x0bb3f4d023f3e10df7feeec5396dc96445f61899";

export default new web3.eth.Contract(abi, address);
4 changes: 0 additions & 4 deletions src/test/test.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/web3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Web3 from 'web3';

const web3 = new Web3(window.web3.currentProvider);

const web3 = new Web3(window.web3.currentProvider);
export default web3;
1,984 changes: 736 additions & 1,248 deletions truffle/build/contracts/Auction.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions truffle/build/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"type": "function"
}
],
"metadata": "{\"compiler\":{\"version\":\"0.4.19+commit.c4cbbb05\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":false,\"inputs\":[{\"name\":\"new_address\",\"type\":\"address\"}],\"name\":\"upgrade\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"last_completed_migration\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"completed\",\"type\":\"uint256\"}],\"name\":\"setCompleted\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/Users/jenilthakker/Desktop/Coding/auction-dapp/truffle/contracts/Migrations.sol\":\"Migrations\"},\"libraries\":{},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/Users/jenilthakker/Desktop/Coding/auction-dapp/truffle/contracts/Migrations.sol\":{\"keccak256\":\"0x525ea46b09fa157a56f0f75a484f88d0f3ad9645406aadce4d84e631096f766e\",\"urls\":[\"bzzr://cef71a9a33d82ef94e686ec7e6805539d226f5c112728356100a6d38a3722b8e\"]}},\"version\":1}",
"bytecode": "0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102db8061005e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a7230582012b6d38f764513f7d1ae544615c507305a6749dc9973ca9c27f09172d2c9cbeb0029",
"deployedBytecode": "0x606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a7230582012b6d38f764513f7d1ae544615c507305a6749dc9973ca9c27f09172d2c9cbeb0029",
"sourceMap": "27:488:0:-;;;116:58;;;;;;;;159:10;151:5;;:18;;;;;;;;;;;;;;;;;;27:488;;;;;;",
Expand Down Expand Up @@ -193,7 +194,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 198,
"referencedDeclaration": 166,
"src": "159:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
Expand Down Expand Up @@ -278,7 +279,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 198,
"referencedDeclaration": 166,
"src": "210:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
Expand Down Expand Up @@ -839,7 +840,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 198,
"referencedDeclaration": 166,
"src": "159:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
Expand Down Expand Up @@ -924,7 +925,7 @@
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 198,
"referencedDeclaration": 166,
"src": "210:3:0",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
Expand Down Expand Up @@ -1375,7 +1376,7 @@
}
},
"schemaVersion": "3.0.11",
"updatedAt": "2019-08-02T20:49:53.307Z",
"updatedAt": "2019-08-31T22:36:54.641Z",
"devdoc": {
"methods": {}
},
Expand Down
28 changes: 11 additions & 17 deletions truffle/contracts/auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract Auction {

// The highest bidder for the auction.
address highestBidder;

function auction() public {
seller = msg.sender;
}
Expand All @@ -21,26 +21,20 @@ contract Auction {
// initializing bidders & bids.
bidders.push(msg.sender);
bids.push(msg.value);

//initializing highestBidder
highestBidder = msg.sender;
}



function determineWinner() public {
uint256 highestBid = 0;
uint256 i;

for (i = 0; i < bids.length; i++) {
if (bids[i] > highestBid) {
highestBid = bids[i];
bidders[bidders.length-1].transfer(
bids[bids.length -1]);
// Reset to a new round of auction.
bidders = new address[](0);
}
}

highestBidder = bidders[i];
highestBidder.transfer(highestBid);

// Reset: for a new auction round.
bidders = new address[](0);
}

function getHighestBidder() view public returns (address) {
return highestBidder;
}
Expand Down

0 comments on commit 0129c43

Please sign in to comment.