Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated App and Server side #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions client/package-lock.json

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

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"axios": "^0.27.2",
"ethereum-cryptography": "^1.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
3 changes: 3 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import { useState } from "react";
function App() {
const [balance, setBalance] = useState(0);
const [address, setAddress] = useState("");
const [privateKey, setPrivateKey] = useState("");

return (
<div className="app">
<Wallet
balance={balance}
privateKey={privateKey}
setPrivateKey={setPrivateKey}
setBalance={setBalance}
address={address}
setAddress={setAddress}
Expand Down
17 changes: 12 additions & 5 deletions client/src/Wallet.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import server from "./server";
import * as secp from 'ethereum-cryptography/secp256k1'
import {toHex} from 'ethereum-cryptography/utils'

function Wallet({ address, setAddress, balance, setBalance }) {
function Wallet({ address, setAddress, balance, setBalance,privateKey,setPrivateKey }) {
async function onChange(evt) {
const address = evt.target.value;
setAddress(address);
const privateKey = evt.target.value;
setPrivateKey(privateKey);
const address=toHex(secp.getPublicKey(privateKey))
setAddress(address)
if (address) {
const {
data: { balance },
Expand All @@ -19,10 +23,13 @@ function Wallet({ address, setAddress, balance, setBalance }) {
<h1>Your Wallet</h1>

<label>
Wallet Address
<input placeholder="Type an address, for example: 0x1" value={address} onChange={onChange}></input>
Private Key
<input placeholder="Type your privatekey" value={privateKey} onChange={onChange}></input>
</label>

<div>
Address:{address.slice(0,10)}...
</div>
<div className="balance">Balance: {balance}</div>
</div>
);
Expand Down
12 changes: 8 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const express = require("express");
const app = express();
const generate=require("./generate")
const cors = require("cors");
const port = 3042;

app.use(cors());
app.use(express.json());

const balances = {
"0x1": 100,
"0x2": 50,
"0x3": 75,
"0477d6d89efe313dcc63599dbe0aff9f7a84129fcd00c8c952b4eba35da41547e25d69132809fe620cbdccf5fcb3f2f053842a302fbf660635c4e45f693732fd8c": 100,
"041e7b0cec9217b3e2604f752f3805f52f10935aa51d8d4e0b1bce953f5cc95768ca298942265994e45695122c8421fb2b24f857cd4a9091f8c2fd75544cdf6dfa": 50,
"048e2bd0844c517a2cf8877c7aa05a737ebfda87581f198e6d84e3e7feb766ca6ccace598e16192081960b4e4cc5ce5a95bdc5bad61a5cd6efdc7550e619f66cab": 75,
};

app.get("/balance/:address", (req, res) => {
Expand All @@ -19,7 +20,10 @@ app.get("/balance/:address", (req, res) => {
});

app.post("/send", (req, res) => {
const { sender, recipient, amount } = req.body;
const { message, signature } = req.body;
const { recipient, amount } = message;
const pk=generate.signatureToPk(message,signature);
const sender=generate.pktoAddress(pk);

setInitialBalance(sender);
setInitialBalance(recipient);
Expand Down
121 changes: 121 additions & 0 deletions server/package-lock.json

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

Loading