Bitcoin Forum
May 06, 2024, 04:42:44 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Dear newbie... you can easily learning bitcoin and blockchain by cooding..  (Read 160 times)
secone (OP)
Hero Member
*****
Offline Offline

Activity: 700
Merit: 501


View Profile
October 27, 2020, 12:36:26 PM
 #1

//module required
const SHA256 = require("crypto-js/sha256");

class CryptoBlock {
  constructor(index, timestamp, data, precedingHash = " ") {
    this.index = index;
    this.timestamp = timestamp;
    this.data = data;
    this.precedingHash = precedingHash;
    this.hash = this.computeHash();
    this.nonce = 0;
  }

  computeHash() {
    return SHA256(
      this.index +
        this.precedingHash +
        this.timestamp +
        JSON.stringify(this.data) +
        this.nonce
    ).toString();
  }

  proofOfWork(difficulty) {
    while (
      this.hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")
    ) {
      this.nonce++;
      this.hash = this.computeHash();
    }
  }
}

class CryptoBlockchain {
  constructor() {
    this.blockchain = [this.startGenesisBlock()];
    this.difficulty = 4;
  }
  startGenesisBlock() {
    return new CryptoBlock(0, "01/01/2020", "Initial Block in the Chain", "0");
  }

  obtainLatestBlock() {
    return this.blockchain[this.blockchain.length - 1];
  }
  addNewBlock(newBlock) {
    newBlock.precedingHash = this.obtainLatestBlock().hash;
    //newBlock.hash = newBlock.computeHash();
    newBlock.proofOfWork(this.difficulty);
    this.blockchain.push(newBlock);
  }

  checkChainValidity() {
    for (let i = 1; i < this.blockchain.length; i++) {
      const currentBlock = this.blockchain;
      const precedingBlock = this.blockchain[i - 1];

      if (currentBlock.hash !== currentBlock.computeHash()) {
        return false;
      }
      if (currentBlock.precedingHash !== precedingBlock.hash) return false;
    }
    return true;
  }
}

let smashingCoin = new CryptoBlockchain();

console.log("smashingCoin mining in progress....");
smashingCoin.addNewBlock(
  new CryptoBlock(1, "01/06/2020", {
    sender: "Iris Ljesnjanin",
    recipient: "Cosima Mielke",
    quantity: 50
  })
);

smashingCoin.addNewBlock(
  new CryptoBlock(2, "01/07/2020", {
    sender: "Vitaly Friedman",
    recipient: "Ricardo Gimenes",
    quantity: 100
  })
);

console.log(JSON.stringify(smashingCoin, null, 4));

learn here for detail
https://www.smashingmagazine.com/2020/02/cryptocurrency-blockchain-node-js/  Roll Eyes
1715013764
Hero Member
*
Offline Offline

Posts: 1715013764

View Profile Personal Message (Offline)

Ignore
1715013764
Reply with quote  #2

1715013764
Report to moderator
1715013764
Hero Member
*
Offline Offline

Posts: 1715013764

View Profile Personal Message (Offline)

Ignore
1715013764
Reply with quote  #2

1715013764
Report to moderator
You can see the statistics of your reports to moderators on the "Report to moderator" pages.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715013764
Hero Member
*
Offline Offline

Posts: 1715013764

View Profile Personal Message (Offline)

Ignore
1715013764
Reply with quote  #2

1715013764
Report to moderator
hatshepsut93
Legendary
*
Offline Offline

Activity: 2968
Merit: 2145



View Profile
October 27, 2020, 03:25:49 PM
Merited by DdmrDdmr (1), PrimeNumber7 (1)
 #2

You can't just copypaste some code, leave a link and call it a useful thread. You're actually showing a bad example to newbies, because they might start thinking that such low-effort posts are acceptable. And generally, starting a thread with only a link and an excerpt from the article is a bad manner, you should always add something from yourself, and write a short summary of the article that you are linking, because not everyone wishes to leave this forum for another resource.

And as for your link, not everyone can code in Javascript, in fact most people probably can't, so this isn't a very useful thing for general public, it would only be interested for people who are already Javascript developers.

.BEST.CHANGE..███████████████
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
███████████████
..BUY/ SELL CRYPTO..
BIT-BENDER
Hero Member
*****
Offline Offline

Activity: 1540
Merit: 702



View Profile
October 27, 2020, 04:43:36 PM
 #3

You can't just copypaste some code, leave a link and call it a useful thread. You're actually showing a bad example to newbies, because they might start thinking that such low-effort posts are acceptable. And generally, starting a thread with only a link and an excerpt from the article is a bad manner, you should always add something from yourself, and write a short summary of the article that you are linking, because not everyone wishes to leave this forum for another resource.

And as for your link, not everyone can code in Javascript, in fact most people probably can't, so this isn't a very useful thing for general public, it would only be interested for people who are already Javascript developers.
I have always been irritated by it -posting links without contributing your understanding from it.
Try providing suggestions with summary
Its like an easy-working way out to thinking to actually be contributing but we don't get to see/know if the poster has read/understood/implemented the post.
And easy additions -has to be personal- to the brought-in article like
+how to use the article
+ risk/problems/solutions
+ newbies -warning-, expert -analysis-
+in relation to -economy, bitcoin/crypto-coin/forum and more.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Trinx01
Member
**
Offline Offline

Activity: 297
Merit: 40


View Profile
October 28, 2020, 04:09:56 AM
 #4

You can't just copypaste some code, leave a link and call it a useful thread. You're actually showing a bad example to newbies because they might start thinking that such low-effort posts are acceptable.
That's right, it is not enough just to copy and paste the whole text and then just include the source not to be called plagiarism.

All people here know how to search through the internet just like what he did, we always tackled this thing in our school that doing this is not the right thing to do, you still need to give your idea about the text that you have given. Your opinion and thoughts are needed.

We may do paraphrasing but with this thread, it is not applicable because it is a whole code, better to do is to give our conclusion or summarization about it.

nakamura12
Hero Member
*****
Offline Offline

Activity: 2268
Merit: 669


Bitcoin Casino Est. 2013


View Profile
October 28, 2020, 04:32:43 AM
 #5

what will that code do?. It is useless if you only copy and paste the code in here and help newbies learn coodibg? You mean coding right?. Why don't we understand how coding works first before doing something not easy. Copying code won't help you learn easily. I tried copying codes before and you won't learn. I have created a website before but did not work and have to self taught myself.

███▄▀██▄▄
░░▄████▄▀████ ▄▄▄
░░████▄▄▄▄░░█▀▀
███ ██████▄▄▀█▌
░▄░░███▀████
░▐█░░███░██▄▄
░░▄▀░████▄▄▄▀█
░█░▄███▀████ ▐█
▀▄▄███▀▄██▄
░░▄██▌░░██▀
░▐█▀████ ▀██
░░█▌██████ ▀▀██▄
░░▀███
▄▄██▀▄███
▄▄▄████▀▄████▄░░
▀▀█░░▄▄▄▄████░░
▐█▀▄▄█████████
████▀███░░▄░
▄▄██░███░░█▌░
█▀▄▄▄████░▀▄░░
█▌████▀███▄░█░
▄██▄▀███▄▄▀
▀██░░▐██▄░░
██▀████▀█▌░
▄██▀▀██████▐█░░
███▀░░
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10550



View Profile
October 28, 2020, 06:09:12 AM
 #6

this is also a terrible code and a bad example.
blocks don't have "indexes" they have "versions" and they don't have "data" they have a list of transactions and the merkle root hash computed from them and placed in the header. the hash is also computed using the header only not the entire block which makes the constructor and the computehash wrong.
the difficulty is also wrong, it is not compared as a "string" but as an integer. this may look like simplification but it is misleading and wrong.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
LTU_btc
Legendary
*
Offline Offline

Activity: 3052
Merit: 1330


Slava Ukraini!


View Profile WWW
October 28, 2020, 10:30:38 AM
 #7

Well, I'm not newbie, but this code doesn't mean anything for me, not sure about newbies. Not everyone here have knowledge about coding, so probably it's not best way to learn about Bitcoin and blockchain and how it works. Especially in the way you did just by copying some code without giving short explanation about it.

MickLichz
Jr. Member
*
Offline Offline

Activity: 56
Merit: 1


View Profile
October 28, 2020, 03:48:02 PM
 #8

The thing those users that has no knowledge or zero understanding in codes will not relate to what your post means you should at least indicate what it is for, and some statement to explain the whole thing.
Peanutswar
Legendary
*
Offline Offline

Activity: 1540
Merit: 1043


Top Crypto Casino


View Profile WWW
October 28, 2020, 04:03:56 PM
Merited by Alucard1 (1)
 #9

Hello mate I think this is not appropriate because

1. Some of the newbies don't other stand code.
2. Don't set aside that they are still newbies.

The objective of the OP is good because he executes the use of the code but still, we must need to deliver the message effectively and not all of them are knowledgeable about these things.

I want to share some of the basic things on the codes. For newbies.

Class() this stores the value of the whole function.
Example. A box of codes

Variable holds the information
Example.
Data
Holding a number or letter
Name : "Peanutswar"

JSON is a compilation of the variable
Example :
Name : "Peanutswar"
Age : "10"
Gender : "unknown"

If else -
If - will use of the condition will true
Else - will use of the condition is false

Example
If (ieat=true){
 Console.log("satisfy");
Else{
Console.log("you will hungry");

While
Is the process will run until does not satisfy the condition.
Example

While (10!=1){
 Console.log("I will eat")
}
*this code will occur an infinite looping of I will eat.

For loop
This is commonly use for looping data.


For(first statement; second statement; increment/decrement)
Example
int a is the start value
a > 0 is a condition
a++ increment

For ( int a =0; a < 3; a++){
console.log("I will learn in bitcointalk")
}

Output :
I will learn in bitcointalk
I will learn in bitcointalk
I will learn in bitcointalk
I will learn in bitcointalk

Console.log() is the printing of the value.



Correct me if made some mistake I just want to share what I know.

You can learn with these also in TutorialsPoint and w3school.
I'm not promoting them but this is a good website for learning programming and HTML.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Alucard1
Full Member
***
Offline Offline

Activity: 574
Merit: 125


View Profile
November 01, 2020, 02:15:49 PM
 #10

...
I am an IT student so I understand the code of yours, this is easier compared to the codes of the OP and I like looping just like what you have used which is the for loop if the person who doesn't have any programming knowledge see this kind of code, for sure they won't understand it and just leave it away but for those who love to gain knowledge about it then better to research programming codes because seeing the code won't help you at all, programming has so many branches and different languages, it is so hard to learn but is worth it to understand.

If I am not mistaken you used the javascript, I just want to add some information, for looping, there are three kinds of loop, which are for loop, do loop, and do while loop.

For loop
Syntax:
Code:
for (statement 1; statement 2; statement 3) {
Actual code:
for (i = 0; i < 5; i++) {
Statement 1 executed only once before the execution of the code block.

Statement 2 defines the condition for executing the code block.

Statement 3 executed every time after the code block has been executed.(incremental/decremental)

Do while loop
Syntax:
Code:
do
   statement
while (condition);
Actual code:
do {
  text += "The result is " + i;
  i++;
}
while (i < 10);

While loop
Syntax:
Code:
while (condition) {
  // statement to be executed
}
Actual code:
while (i < 10) {
  text += "The result is " + i;
  i++;
}

Yamust
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile
November 02, 2020, 08:03:13 AM
 #11

Hello, I'm just new here, still I don't know where should post and ask some question about this bitcointalk and about bitcoin. What should I do fisrt and how can I do it. Please help me. Thank you in advnce.
Peanutswar
Legendary
*
Offline Offline

Activity: 1540
Merit: 1043


Top Crypto Casino


View Profile WWW
November 02, 2020, 08:10:25 AM
 #12

Hello, I'm just new here, still I don't know where should post and ask some question about this bitcointalk and about bitcoin. What should I do fisrt and how can I do it. Please help me. Thank you in advnce.

Hello, please read our forum rules and other information you must know I provide some of the important things you must learn and know.
https://bitcointalk.org/index.php?topic=703657.0
https://bitcointalk.org/index.php?topic=178608.0

We are making this forum having a good reputation, Also if you have question you can freely open to our Beginners & help.
Base on your construction of sentences, I recommend you to use a Grammarly to avoid giving an inappropriate reply to a thread.


█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Yamust
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile
November 02, 2020, 09:10:08 AM
 #13

Thank you for this link I can easily know what topic should I read first. Hope and I think this will help me a lot to learn about this.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!