Giter Club home page Giter Club logo

naivecoin's Introduction

Naivecoin

The repository for the naivecoin tutorial: https://lhartikk.github.io/

npm install
npm start
Get blockchain
curl http://localhost:3001/blocks
Mine a block
curl -X POST http://localhost:3001/mineBlock
Send transaction
curl -H "Content-type: application/json" --data '{"address": "04bfcab8722991ae774db48f934ca79cfb7dd991229153b9f732ba5334aafcd8e7266e47076996b55a14bf9913ee3145ce0cfc1372ada8ada74bd287450313534b", "amount" : 35}' http://localhost:3001/sendTransaction
Query transaction pool
curl http://localhost:3001/transactionPool
Mine transaction
curl -H "Content-type: application/json" --data '{"address": "04bfcab8722991ae774db48f934ca79cfb7dd991229153b9f732ba5334aafcd8e7266e47076996b55a14bf9913ee3145ce0cfc1372ada8ada74bd287450313534b", "amount" : 35}' http://localhost:3001/mineTransaction
Get balance
curl http://localhost:3001/balance

Query information about a specific address

curl http://localhost:3001/address/04f72a4541275aeb4344a8b049bfe2734b49fe25c08d56918f033507b96a61f9e3c330c4fcd46d0854a712dc878b9c280abe90c788c47497e06df78b25bf60ae64
Add peer
curl -H "Content-type:application/json" --data '{"peer" : "ws://localhost:6001"}' http://localhost:3001/addPeer

Query connected peers

curl http://localhost:3001/peers

naivecoin's People

Contributors

lhartikk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

naivecoin's Issues

Missing Proof of Work

This blockchain would resemble real blockchains much more if it implemented a proof of work challenge whereby a node looking to add a block to the blockchain would have to find a nonce that could generate a specific hash. For instance, if a node wanted to add a block, and the previous hash was "abc", then it would have to find a number x such that when that number is appended to the byte-stream of the block it wants to hash, the hash of the block would begin with a zero, say "0ewbv". This would resemble bitcoin more closely.

issue during mining a block

This happened when i tried to mine a block in naivecoin-vue frontpage. The block number was 11 and I tried to add a block by mining.
(https://user-images.githubusercontent.com/31149915/37551904-23df1ae4-29e5-11e8-88ba-92952f72c348.png)

The following error occurs:
(https://user-images.githubusercontent.com/31149915/37551901-f0d8528c-29e4-11e8-9c35-c589b895d5f7.png)

and btw, i wonder if there is a way to communicate with you and ask you serval questions about your amazing codes?

transaction.ts issue

I think in hasDuplicates() function: const groups = _.countBy(txIns, (txIn) => txIn.txOutId + txIn.txOutId);
Why we need calculate txIn.txOutId two time?
I think it should be: const groups = _.countBy(txIns, (txIn) => txIn.txOutId + txIn.txOutIndex);

feature request : bitcoin working wallet

Hi and thanks for this naive and very elegant proof of concept.
How much work do you think is needed to go from this POC to a fully working bitcoin implementation ?
Thanks !

-0-

Is 2 an arbitrary number or where does it come from?

Error in file transactionPool.js

Hi,
I have cloned your code in my environment and follow the readme ,when i type npm start ,some errors were found.:
/var/www/test/naivecoin/src/transactionPool.js:39
transactionPool = _.without(transactionPool, ...invalidTxs);
SyntaxError: Unexpected token ...

What is wrong with it ?Why there is '...' in front of 'invalidTxs',please help me.

Transactions.ts problem

When i try to compile provided code i get following error.
transactions.ts(158,24): error TS2339: Property 'find' does not exist on type 'UnspentTxOut[]'. transactions.ts(174,27): error TS2339: Property 'find' does not exist on type 'UnspentTxOut[]'. transactions.ts(246,18): error TS2339: Property 'from' does not exist on type 'ArrayConstructor'. transactions.ts(333,25): error TS2339: Property 'startsWith' does not exist on type 'string'.

A bug at line 209 of the blockchain.ts , must return false

look at the location :
//must return false
return false;


const hasValidHash = (block: Block): boolean => {

    if (!hashMatchesBlockContent(block)) {
        console.log('invalid hash, got:' + block.hash);
        return false;
    }

    if (!hashMatchesDifficulty(block.hash, block.difficulty)) {
        console.log('block difficulty not satisfied. Expected: ' + block.difficulty + 'got: ' + block.hash);
        //must return false
        return false;
 }
    return true;
};

Redundant Validity check.

aUnspentTxOuts.find((uTxO) => uTxO.txOutId === txIn.txOutId && uTxO.txOutIndex === txIn.txOutIndex);

Why is the equality between the unspent transaction id and the new transaction uxto reference id being checked for twice? Why can't you just do uTxO.txOutId === txIn.txOutId instead of uTxO.txOutId === txIn.txOutId && uTxO.txOutId === txIn.txOutId?

NOT AN ISSUE: Ideas for improving when you are done with the tutorial!

Hello!
If you are here, you must have completed the tutorial :)

Here are some ideas of where to go from now... In my opinion! Please share your ideas below if you want.

  • Add automatic mining
  • Share peers via p2p (beware about your wallet connecting to itself!)
  • Add a list of known peers to connect to on wallet boot
  • Make a UI to list, add and remove peers
  • Endpoint to show last block
  • Support network confirmations in UI
  • List my transactions (FROM my address, TO my address)
  • List transactions (FROM an address, TO an address)
  • Add a difficulty validation, so that people don't spam Difficulty 1 blocks and overtake your precious chain!
  • Restart mining if you get a newer block
  • Write your blockchain to disk and load it on boot
  • implement Proof of Stake or Extended UTXO

Typo in Chapter 1

You've stated in your Architecture section that two servers should be exposed: an HTTP server and a WebSocket HTTP server. Great article though!

Wallet Uniqueness

Hi, thank you for the naivecoin and naivechain tutorials!

In the tutorial, when creating the wallet, generating a private key, this is basically how that user will interact with the network right? Their 'credentials' so to speak.

What is there to guarantee that someone else won't generate the same private key one day? I'm still kind of going through it all, but as far as I can tell we're just saving this key to our local hard drive. So is there even a way to check the network to make sure the generated keys are not repeated?

EDIT: If anyone else comes to this with the same question, as far as I can tell most blockchain wallets seem to simply rely on probability to ensure uniqueness in the generated private keys. According to some of the stuff I read the possible keys, for Bitcoin as an example, are so vast that the odds of generating a duplicate key is astronomical and unlikely to happen even with billions of users over multiple lifetimes.

Going to leave this here in case anyone with a better understanding does decide to answer. For some reason I still don't feel comfortable with that answer.

Unable to hit sendTransaction api

Hello @lhartikk
I am newbie and i have downloaded your source code and able to make nodes working and apis mentioned in Naive-chain tutorial.
But now when i moved forward to Naive-coin tutorial, In this project i am able to hit apis from Naive-Chain but apis from Naive-coin is not working. For example: I am hitting send transaction api but it throws me error :

<title>Error</title>
Cannot POST /sendTransaction

Is there something i left or is there something missing in code. Anyone facing same issue? Please reply asap

Curl no longer interacting with the server

Hi @lhartikk ,

after running npm install, npm start the server is non-responsive to curl commands. Has something changed between your tutorial code and instructions on how to interact with the HTTP server between writing the tutorial and now?

Thanks, Canaan

Code no longer works with current package.json

The current version of code actually does not work. ):
The issue is related with the Elliptic version required in package.json.

The npm install command will try to install "^6.4.0" Elliptic version, which refers now to the 6.4.1 version. This Elliptics version have some different methods call, implying that the code no longer compile.

One alternative is require the specific Elliptic version, e.g.:
"elliptic":"6.4.0"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.