lhartikk / naivecoin Goto Github PK
View Code? Open in Web Editor NEWA tutorial for building a cryptocurrency
Home Page: https://lhartikk.github.io/
License: Apache License 2.0
A tutorial for building a cryptocurrency
Home Page: https://lhartikk.github.io/
License: Apache License 2.0
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;
};
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.
Is 2 an arbitrary number or where does it come from?
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.
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'.
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"
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 :
Cannot POST /sendTransaction
Is there something i left or is there something missing in code. Anyone facing same issue? Please reply asap
Nice and clear article for get started in blockchain and cryptocurrency!
I find out there might be a typo in https://lhartikk.github.io/jekyll/update/2017/07/13/chapter2.html
I consider it should be
In the below example, the “Chain B” is the “correct” chain although it has fewer blocks, instead of fever
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?
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
I followed the Readme and type below 2 commands but encountered error:
curl -X POST http://localhost:3001/mineBlock
curl -H "Content-type: application/json" --data '{"address": "04bfcab8722991ae774db48f934ca79cfb7dd991229153b9f732ba5334aafcd8e7266e47076996b55a14bf9913ee3145ce0cfc1372ada8ada74bd287450313534b", "amount" : 35}' http://localhost:3001/mineTransaction
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.
Line 162 in 35237fb
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?
Why not just comparing hashes instead of stringified objects?
const isValidGenesis = (block: Block): boolean => {
return JSON.stringify(block) === JSON.stringify(genesisBlock);
};
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 !
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.
You've stated in your Architecture section that two servers should be exposed: an HTTP server and a WebSocket HTTP server. Great article though!
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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.