With JSON how do I know the amount that was LAST sent to a given address? I am trying to build a script that will give me the amount a user has sent to a given bitcoin address. Currently this data is in JSON format.

How can I use this JSON data to know the amount that was LAST sent to a given address?

For the moment I have as a return of a submitted form:

$userIDsent = $_POST['userID'];
$adrsBTCsent = $_POST['adrsBTC'];

$bcInfo = json_decode(file_get_contents("https://blockchain.info/address/". $adrsBTCsent ."?format=json"), true);

$nombre_de_transac  = $bcInfo["n_tx"];
$valeur_en_satochi = $bcInfo["total_received"];

If ($nombre_de_transac > 1){
    /* more then 1 transaction for that BTC adds. I need to know what is the amount last sent and NOT the total amount used on that address */

} else {
    /* 1 transaction this address is new so let's get the amount of BTC sent */
    echo "The user ".$userIDsent." has sent ". $valeur_en_satochi . "uBTC";
    echo "bra, bla, bla lets continue";
}

Thank you for your help.

You can also use the filter GET parameter to ensure that the first transaction is one where the address receives bitcoins and not one where the address spent bitcoins and the limit parameter to only fetch one transaction (the latest).

For example https://blockchain.info/address/1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp?filter=2&limit=1&format=json

To get the amount sent, you'll have to filter outputs to get the one sending BTC to the address you're interested in and then get the value field (divide by 100,000,000 to get the amount in BTC).

If you are doing this as a way to get notified of incoming payements, I highly recommend you to use the Receive Payments API as it is dedicated to this use case.


What is a fee market? Does it mean that blocks should be full, esp. after several halvenings? As we all know, Bitcoin had experienced an unprecedented long-lasting congestion period in 2017. This seems quite horrible to some people generally, but it seems that such phenomenon was on the contrary considered as a positive sign by developers, for example:

  Personally, I'm pulling out the champaign that market behaviour is indeed producing activity levels that can pay for security without inflation, and also producing fee paying backlogs needed to stabilize consensus progress as the subsidy declines.

I've heard that is about a strategy called "stable fee market"(might be inaccurate, sorry). So, I'm courious that does that mean the blocks should be kept full in order to keep Bitcoin safe? Is it merely a compensation of declining block subsidy? Is there any deeper reason behind?

Also, I wonder how could Replace-By-Fee take effects?

The fee-market refers to the tension between

1) users who want to have their transactions confirmed as quickly as possible and ...
2) miners, who can only mined blocks with a fixed confirmation capacity (1mb, 4mWeight).

Naturally, it is in the interest of a miner to construct a block to mine from the mempool which results in the maximum block reward for the miner.

So when blocks are full, this tension between demand for confirmation and limited supply of block space will be resolved at a certain price. At a given price, there may or not be a miner who is willing to include a given transaction in its next block. If not, one simply needs to observe the (clearing) price at which transactions are being confirmed.

The fee-market is therefore between confirmation-seekers (users) and confirmation-providers (miners).

If fees rise because blocks are full, certain transaction amounts with Bitcoin will become unfeasible, because the fees in relation to the transaction amount are too high. So the remaining transactions will naturally be of higher amounts which still justify the market fee price. As long as confirmation capacity is limited and fixed, this will remain true.

This also has nothing to do with halvenings. The inflation/subsidy schedule obviously contributes to a miner's reward, but it independent of any transaction demand, and represents an initial mechanism to distribute coins.


What happens to Private Key on Payment If I pay someone in bitcoin, presumably I have to utilise both my private and public key in some way, and presumably this has to be verified by the network.

Now does the network thus obtain my private key as part of the verification process?  If not, how do they verify without it and if they do, does this mean my private key is now compromised?

The network does not obtain your private key.  That is why it is called "private", and this is the whole reason that digital signatures are secure

When someone pays coins to you, the transaction includes your address, which is a hash of a public key.  Public keys and private keys come in matched pairs, and to spend the transaction, you create a new transaction that is digitally signed using the corresponding private key.  The signature incorporates your public key, and anyone on the network can verify that it is valid.  A valid signature cannot be created without access to the private key, but the private key is not part of the signature and cannot be recovered from it.

If future transactions are paid to your address, you're still the only one who can spend them, so long as you keep your private key secure.


How to calculate the checksum of an extended public key? Very difficult to find definitive info on this.

From what I can find on google and looking at BIP32 it seems like the process to calculate a checksum for an extended key is to decode the base58 string to data, then perform a double sha256 on the data and the first 4 bytes from the double hash are the checksum.

I am trying to take in a non xpub (vpubs, upub ypub etc) and convert it to an xpub/tpub programmatically. Currently I have it working but the last 6 digits of the xpub are always incorrect, I am assuming this is the checksum?

In order to correctly calculate the checksum do I remove the prefix first, then remove the existing checksum then do the double sha256 on the stripped down extended key or do I keep the new xpub prefix and then perform the double sha256? Or am I completely wrong in my assumptions here?

Thanks in advanced!

it seems like the process to calculate a checksum for an extended key is to decode the base58 string to data,

If raw_xpub = version + depth + fingerprint + child + chain + DATA
than to make the checksum you need to do doublehash of xpriv/xpub (sha256), in python:

hashed_xpub = hashlib.sha256(raw_xpub).digest()
hashed_xpub = hashlib.sha256(hashed_xpub).digest()

and then take the checksum as first 4 characters (0 to 3) and add it at the end of the raw xpub:

raw_xpub += hashed_xpub[:4]

Finally, run it through Base58 to encode it. I think you've might performed base58 operation too early based on your question. It's the last step in the process.


Does the inability to spend only part of a transaction result in "too many" extra transactions? I understand that I can only spend the amount of a full transaction associated with an address. Often this will result in change being sent to a change address that I provide. One question at this point is, why does the receiver bother sending back the change. Do you send way more than the original cost for an item?

Say they do, don't they have the same problem, not having a transaction for the exact amount so that they too might end up sending too much to you, so that a cycle of change happens - what could have been one transaction ends up being many which seems like this is a burden on the system?

Why does the receiver bother sending back change?

This assumption is wrong. Nevertheless, you are correct saying, that you need to spend the whole transaction input (UTXO) balance on your address, but the person who makes the change is the sender, not receiver.

Example, You have unspent balance (UTXO) of 1 Bitcoin and you want to pay 0.2 BTC for coffee. You create a transaction spending 1 whole Bitcoin to two separate receivers. 0.2 BTC (tx output) goes to merchant and 0.7 BTC you direct back to your address (the change). The difference between UTXO and sum of tx outputs is called fee, in this case 0.1 BTC.

  Does the inability to spend only part of a transaction result in “too many” extra transactions?

No, since it is still 1 transaction with just two output in case there is a change. No extra transaction is made.


What happens if Bitcoins are lost Since there are a finite number of Bitcoins that can be created, I am wondering what happens if some of the coins are lost. My questions are three fold:

How do you define a "lost" coin? For example if a bank note that was in my pocket is not there anymore (provided that I did not spend it), I know I lost it.
How does the network know a coin is lost?
How would the remaining coins value if some are lost? For example, assume there are 10 coins in total in circulation each worth 100 usd, the total spending power is 1000 usd. If say 2 of them are lost, are they assumed to be taken out of the circulation for good or someone can pick them up and reuse them. I guess in the first case the value of the remaining coins are worth 125 usd each due to fewer coins in circulation while in the latter case the value of each case would stay the same (this comes back to the second question of if the network is aware of the lost coins).

I come from non-programming background so appreciate clarification.

Thanks

Since the "ownership" of bitcoins is essentially tied to having knowledge of the private key for the address they are stored against, it's very difficult to prove that nobody knows the private key.

However, it is possible to send bitcoins to an address with no private key, essentially destroying them. Details here: How to generate a valid bitcoin address for destroying bitcoins?

To answer your 3 questions:

There is no accepted definition of a lost bitcoin that I'm aware of, and it's unlikely there will be one because of the difficulty in providing proof.
The network doesn't know whether the private key for some bitcoins have been lost.
The value is based on market demand. From this perspective, bitcoins that aren't currently offered for sale are the same as lost coins until they are offered up for sale, at which point the price is affected. Though individuals do have the capability to prove they own bitcoins without offering them for sale, they rarely do so, so you'll probably never be able to find out much about which unspent bitcoins are still being quietly held and which are lost.


How to send bitcoins from one address to another without wallet I generated btc address and put some coins into it. Now I want to send coins to another address. I can't find any infomation about how I can do it. I don't have wallet, I only have address: public key and private key.

If you have your private key, you are able to import it into a wallet and send the coins from there. The trustless way to do this would be to start your very own Bitcoin and user the Import Private Key RPC call. You then would be able to use the Send To Address RPC call to send the coins.

Depending on your necessary security level, it may be easier to just use an online wallet service like BTC.com. They have instructions available for importing private keys as well: https://help.btc.com/hc/en-us/articles/360002934354-How-do-I-import-my-private-key-into-the-wallet-


How is ethereum related to bitcoin? Is ethereum related to bitcoin? does any one know weather they are related or not.

Bitcoin is a cryptocurrency. It runs on blockchain technology. Ethereum is another independent cryptocurrency that runs on blockchain technology as well.


Which is the better estimator for future mining intervals, the 10 minute protocol target or the observed, historical average? The Bitcoin protocol is designed so that the network difficulty is periodically adjusted so that new blocks are mined on average every 10th minute. However, looking back the last 10 years, it appears the observed, average mining interval is 567.35 seconds. I calculated this by subtracting the timestamp of block nr. 573,795 with the timestamp of block nr. 0 and dividing by 573,794. I know block timestamps aren't that accurate, but this error should be negligible.

Bitcoin mining can be modeled as a Poisson process with certain simplifying assumptions. If I've done the math right, the 95 % confidence interval of a Poisson process with λ = 1.0575 (historical average nr. blocks mined every 600 seconds) and n = 573794 (current nr. of historical block intervals) allows for an actual mining interval no higher than 568.1 seconds, an error bound which is a long way from the 600 second block interval predicted by network difficulty.

I'm aware of at least one reason why there's a discrepancy, and that's the 2016 block difficulty adjustment interval. This was discussed and answered in a relation question here. But is this the only reason why historical block intervals are shorter than the mathematically predicted block intervals? If we experienced a long period of consistent decline in network hash rate, would we see a similar, opposite effect, where the observed block intervals consistently exceed 600 seconds?

Bottom line question is... for block intervals in the future, is it best to assume the target block interval of 600 seconds, or an interval that is slightly lower or higher than this? If so, how much? This has implications, e.g., for designing predictive time series models in finance.

For a good portion of its history the bitcoin network has seen continuous increases in difficulty, which warps the average block time to be below 10 minutes until the next difficulty adjustment. If the reverse were true the block time would be longer in kind.

This latency serves to protect nodes against isolation attacks where you could otherwise disconnect them from their peers and wait until their relative difficulty dropped to a suitable level for you to mine blocks at.

The best estimator of the interval is probably to look at the current window and make a guess as to the direction of change, but this is very error prone due to the low sample size of the block interval.


How to calculate fee in BitcoinJS raw transaction? I have a transaction with 3 inputs and 2 outputs. 1output is the recipient and the other output is change address. How should I calculate the fee and apply it to output?

The TX fee is the difference between the totals of all the input values and all the output values. If you are looking at a single TX you can see all the output values, but how do you get the input values? They are not included in the TX itself. What you must do is look up the UTXO being spent by each TX input and total their values. (The data structure used to track and process all the input coins is called a "view").

Note that there is no "applying a fee to the output". A TX has no extra fee field or property, and the fee itself does not occupy an entire output.

If you are constructing a TX where the input values equal exactly the output values, you "include" a fee by reducing the value of one of the outputs.


Bitcoin core v0.19.0.1 automatically prunes? Just finished syncing the whole blockchain after days and I realize the bitcoin settings were "pruning", which means I cannot use it as a wallet.

is it the normal behavior of bitcoin core v0.19.0.1 to automatically prune the blockchain ?

No, the default behavior of bitcoin core v0.19.0.1 is still the non pruning mod.

You should check your bitcoin.conf file depending on your operating system there is a line about pruning which should be something likeprune=550 in your case, just put a # to deactivate it again like #prune=550.


Decentralized product inventory (instead of simple orderbook) I am thinking of creating a decentralized market place with public bidding. AS far as I have researched all cryptocurrencies and such only offer public ledgers with simple orderbooks. The only data about the item you are exchanging is value like BTC->USD or USD->BTC.

I was hoping to have a decentralized public market for more complex products which have many properties (let's call them CPU, memory, bandwidth, storage and lease time). In this case, you would not bid against a single value (price), but define the acceptable parameter ranger for your bid e.g. 30x units with > 512 MB memory, 1 MBit/s bandwith at the price of 1 USD/unit.

Then the ledger would go through the offers and match ones available on the market. Then trade parties would exchange private keys, so that the buyer would get the access to the item. I have no idea yet how, but probably the buyer would have an encryption key in the bid and if the bid goes through then the seller would encrypt a reply to the buyer using this key (the buyer can only decrypt).

As I am still in early phases of my research, I was wondering is there any prior art in this kind of crypto markets? Preferably the ledger data and the orders are public in consensus or blockchain, so that the there is no single point of failure in the system.

Thus far I have researched

NXT
Stellar
Bitshares X
OpenBazaar (this looks promising but orders and inventories are not decentralized ATM)
Ethereum (well this one is still much in baking)

I think Ethereum is ideal for this.  As you say, it's not ready for prime time yet. But I think it offers the most flexible toolkit for managing orders in a truly decentralized way. You can create and manage arbitrary database structures that are secured on the blockchain.

I wrote a toy digital artwork market using Ethereum -

http://robmyers.org/2014/07/24/ethereum-art-market/


When thinking about e-currency in a general sense, what features discourage black market usage, but promote anonymity? I'm interested in e-currency that discourages black market usage (child porn, meth deals, etc) but allows for anonymous operation (donations to charity, buying a pizza, viagra, or other health issues)

What pre-existing work exists that researches applicability of various "controls" into e-currency systems such as e-cash, Bitcoin, Open Transactions, etc.  And by "controls" I mean:

Psuedo anonymous user registration
Usage "escrow" allowing third party audits or reviews of transactions
Anything else that would be resisted by the Bitcoin purist.

I'm interested in any example you can think of, links to Bitcoin Talk, or any other whitepaper that discusses ways to legitimize e-currency to a moderate fiscal conservative.

The issuing of currency by a central authority discourages black market usage in a sense that all coins in the system can be tracked by the central authority - with AML and KYC policies.


How would debt work in a bitcoin only economy, and why would anyone ever spend? Been keeping track of BTC for a while and have always had these nagging questions about its feasibility as the "future" of currency. I like all the not tracked, no third party involvement, etc (i.e. all the advantages of having an online currency that should most of the time be safe).

However, in economic terms I have always had a hard time getting my head around how it would feasibly work as the prime currency of a country (to keep it simple).

I guess the closest analogy there exists of such a system is the gold standard right way back when. However, and please correct me if I'm wrong, the issues with the gold standard, principally that when theres no more new gold, theres no more growth, doesn't apply to bitcoin. From posts on this sub and others, it seems that the vision is that when bitcoins stop being made, whenever more money supply is needed, the demand for bitcoin will increase and thus price will as well, thus allowing for a smaller fraction of a bitcoin to be worth more (please tell me if I am understanding this very incorrectly). For example, .01 bitcoins at bitcoin price of 50 dollars isn't much but .01 bitcoins at current bitcoin price is nice.

Thus, in an all bitcoin economy, this sort of argument would imply the price of bitcoin will continue to rise forever, as long as there is growth (i.e more demand for me bitcoins).

So that doesn't really make much sense to me. Growth in this crypto only world doesn't make much sense to me. . The thought experiment that I have been slowly developing but I can't seem to figure out (probably because of lack of bitcoin knowledge and effort) goes as follows:

Say we have gotten to cap of 21,000,000 bitcoins in the crypto-currency only economy (lets contain it to one country). Lets say that 1 bitcoin = 1,000,000 dollars - I know tha it doesn't make sense to compare it to dollars in a crypto only economy - so lets say instead that .001 bitcoins gets you a very very nice high quality TV. So thats the bitcoin relative price context. Now lets say that our crypto economy is doing well, people are working yea yea and are getting hired and productivity is up and so wages are up (woohoo!), so companies have to pay more bitcoins to their workers. -Here is my first confusion in a bitcoin economy-. In our fiat currency economy, when this happens, companies usually borrow money from banks (who were given it by printing money from FED) and they can fund these larger wages and hire-ings and technology advancement (we could obviously discuss the merits of having inflation baked into growth into our current system, but its not really the subject). Question: how is this planned to function in a bitcoin only future???

Is the price of bitcoin suppose to increase here, so that a smaller percentage of the bitcoin, (i.e. 10% of ancient bitcoin price, i.e. .0001) can buy the same tv as before thus in essence having 10x the money supply (in my hypothetical scenario here). If this is the vision, then what are the mechanisms for the increase in bitcoin price? How is the relative price of bitcoin compared to all goods actually increasing (demand by whom?).

Second Question - if what I suppose in the first question is in fact the vision (please correct me if im wrong!), why would anyone ever spend?

If I know that when there's growth, the relative price of my money goes up, I will just never work and wait for growth to drive my bitcoin price up in effect making me richer by sitting there (I may have not understood something really fundamental here cause this really just doesn't work like that does it?).

Essentially this scenario is the one that I've been trying to wrap my head around. I don't expect some full holistic answer to the whole scenario, just want to understand if this is how bitcoin believers envision an economic system based crypto currency behaves, and how they actually envision it. thanks for any input! Also, If I have stated any complete fallacies or falsehoods, let me know, I think it is at least clear what my question is.

Question: how is this planned to function in a bitcoin only future???

They can use their assets as collateral for the loan.

The price of Bitcoin (measured in chicken eggs, for example) doesn't necessarily need to increase when somebody takes out a new loan. The price of fiat doesn't change when people take new loans either.

(If workers become more productive and their pay correspondingly increases, the employer may require more money to fund their working capital, but their cost structure doesn't change - the workers help them earn more and the employer pays them approximately the same percentage of their earnings as before. There it is unlikely that everyone would have to use Bitcoin - if Bitcoin gets used on a large scale, that means multiple crypto-currencies would be in circulation.)

  Second Question - if what I suppose in the first question is in fact the vision (please correct me if im wrong!), why would anyone ever spend?

Gold mining generated approximately the same amount of new coins as Bitcoin mining and people would still spend their gold (and silver and stock certificates and diamonds and other savings and assets).

Things worked well before today's fake fiat money existed, and will work equally well after it gets destroyed.

You can learn about it from books and materials discussing how it was before central banks instituted state-sponsored plunder.


How does the architecture prevent someone taking over by running a several billion clients? I'm new to bitcoin and was wondering: As far as I know, bitcoin relies that the majority of the users is to be trusted.

Why is it not a problem then if someone starts up billions of clients, eg. a data center owner? Seemingly a single entity could take over the whole network. What is the bitcoin feature that is the counter-measure here?

The majority needs to be trusted, but not weighted by their number of software instances, but by either computational power or economic power, depending on the context.

The main technical assumption is that the majority of hashrate is not trying to attack the network. So an attacker would need to purchase and operate more hashrate than the rest of the network combined; this isn't easy.


Using seed to send bitcoin from a wallet's specific private key I'm new to bitcoin and I've recently been reading on the concept of wallet. If I understand correctly, a wallet is a collection of one or more pairs address + private key (an address is where BTC can be sent to, and a private key is used to spend BTC from its associated address). I'm not sure if there is something between the private key and the address known as public key.

If I understand correctly, the difference between nondeterministic wallets and deterministic wallets is that with non-HD wallets each pair "address + private key" is generated separately, whereas with HD wallets all pairs "address + private key" are generated with a single list of words known as seed.

I'm interested in HD wallets but I know almost nothing about them and all the terminology I've found on the internet is very confusing to me. I've found terms like BIP39 Mnemonic, BIP39 Passphrase, BIP39 Seed, BIP32 Root Key, Master Private Key, Derivation Path, BIP44, m/44'/0'/0'/0/0, and so on (see iancoleman.io/bip39, for example). I'd like to be able to organize this into something that makes sense and I can understand.

Once I've created an HD wallet and I have a list of pairs "address + private key", how can I access it and spend funds from a specific private key from the list? Which software shoud I use and what is the easiest way to do it without compromising security?

You can use any BIP39 compatible software to enter a mnemonic (12-24 words) and turn it into a seed. Seed is just a number between 1 and 2^256. You can then use this seed to create a Master Private Key. This key then serves as the root of a chain used to create other private keys based on a derivation path.

The whole process is deterministic so same mnemonic and same path will always lead to the same key. Once you have a normal private key you can import it to any bitcoin client and access the funds as usual.


How do the faucets earn money? There are quite a lot of bitcoin faucets on the Internet. They give away bitcoin for free, but where do they come from? Won't the faucet operator lose money?

I imagine different faucets have different business models. The ones I've seen either show you ads, or make you solve captchas (which has potential value to spammers, etc).


Permissioned or Permissionless blockchain? Which one is PoS more adapted for? Since in proof-of-stake (PoS) there is no mining process, according to functionality of permissioned and permissionless blockchains, which type is PoS more adapted for?

In the other words, is a PoS-based public permissionless blockchain as secure a PoW-based public permissionless blockchain ? Or Do we need to restrict the permission for the transactions validation to a limited permitted and known validators (i.e. private permissioned blockchain) ?

The term "permissioneless or public blockchain" is referred to as a blockchain platform in which a user does not have any permission for using (sending transaction) or participating in validating transactions process. For example, Bitcoin and Ethereum are public permissionless blockchain, such that they are open to everybody for both sending transaction and participating in validation of transactions (i.e. PoW process).
On the other hands, "permissioned blockchain" allows the network to appoint a group of participants in the network who are given the authority to provide the validation of blocks and transactions, meaning that there is an an access control layer to allow certain actions to be performed only by certain identifiable participants. Since access to this type of blockchains is not open to everybody, unlike Bitcoin or Ethereum, they are usually called also private blockchains. For example, Ripple and Hyperledger Fabric are permissioned blockchain.

If you need additional explanation for more clarification, kindly let me know to extend the question.

Frankly, I don't think your definitions are useful. But by your definitions, PoS makes a network permissioned by definition. In a proof-of-stake network, you can only participate in the validation of transactions if you possess the token, which you can only get from someone else who has the token and chooses to give it you. By your definitions, that makes the system permissioned.

Again, I don't think your definitions are useful.

To propose more helpful definitions:

A system is permissionless or public if it permits open participation in both the submission of transactions and the choice of transactions to make forward progress on. There must be no special permissions required to submit and execute transactions beyond the possession of some way to pay transaction fees, and this must (in actual practice) be widely and easily available to anyone who makes a reasonable effort to acquire it. The method in which the ledger makes forward progress must justify a reasonable expectation that hard censorship will not occur -- that is, anyone who submits validly signed transactions to the network should be able to reasonably expect them to execute without having to worry that some particular clique or group can decide to disallow their transactions specifically.

A system is permissioned or private if it does not permit open participation in either the submission of transactions or the choice of transactions to make forward progress on. That is, submitting a transaction requires some permission beyond mere possession of a widely-available, anti-spam asset or participants cannot reasonably expect the system to resist censorship, that is, not all participants have reasonable assurance that their transactions won't be discriminated against in a way that significantly affects their ability to use the system and get its benefits.


Is there's anyway to get fee estimation with vbyte instead of KB using "estimatesmartfee" RPC command? I'm using Bitcoin-core RPC command to get current fee rate, but it returns the fees in KB, I would like to get fee rates in vbyte is that possible?

It is of course already using vbytes; anything else doesn't make sense. Almost everywhere Bitcoin Core reports transaction sizes, they're reported in vbytes (for non-segwit transactions, 1 vbyte = 1 byte, so it was a transparent and compatible update).

However, the unit Bitcoin Core uses is "BTC per 1000 vbyte" rather than the currently more common "satoshi per vbyte".

A Bitcoin Core reported feerate of 0.00123456 BTC/kvb corresponds to 123.456 sat/vbyte.


What will happen to bitcoin if the world population increases? I've been trying to find an answer to this question but without success. I have a question on scaling, but not of the technical kind.

Assume that the entire world switches to using bitcoin as its only form of money. What will happen with the fixed number of 21 mil bitcoins in an ever increasing population on the globe?

Will they just distribute thinner and thinner to all the people? Will its value increase? Will people just get paid a salary of 0.0000000132 BTC (or similar) in the future?

The amount of bitcion in circulation does not increase or decrease based on human population.  So, yes, it will likely be distributed more sparsely among people if the world's population increases.

However, bitcoin is only divisible to 8 decimal places, and your example uses 10.  It's also difficult to say what role Bitcoin will play as far as global currencies go, so it is unwise to assume that an amount as small as 0.00000001 will be equivalent to a modern day yearly salary (or whether Bitcoin will be used for salaries at all).  Speculation like that is off topic in this forum, which is why you've received some close votes.


do isolated blocks create forks in block chain? (with forks I mean branches that are no longer valid) If yes then how does the node redeem itself? I'm a newbie to cryto and wanted understand this.
what happens to the  chain when the isolated block is formed (in case of a double spend) ? Since chains only add blocks that come from the  longest running chain. it could be easily possible that initially 2 nodes proposed 2 blocks at the same time of the double spend attack. so

Node A -Block A(Double Spend)

Node B- Block B (Genuine)

Both have same length at this time but Node A decides to go rouge.

Lets consider Node C is close to Node A and hears block A. it adds it to it's block Chain. now another Node D hears about both Block B and A and decides to add A since it's coming from the longest blockchain. Now, It's a successful double spend if the customer didn't wait for any validations.
(But the money is only spend once as we can see Block B is not accepted by any other blocks)

In this case Block B is orphaned.. How does not Node B redeem itself?? How does the Node B add new chain to it's orphaned Block. I guess the orphaned one is just left there and the new Node is added from the previous block.

For easier understanding:I was considering one transaction per block. ;)

  Edit: Anyone Coming to this page may find this Flow helpful:

  1) New transactions are broadcast to all nodes.

  2) Each node collects new transactions to form block.

  3) Each node competes with one another to  solve the  mining puzzle
  (Proof of Work)for its block.

  4) When a node cracks the puzzle, it broadcasts the block to all
  nodes.

  5) Nodes accept the block only if all transactions in it are valid and
  not already spent.

  6) Nodes express their acceptance of the block by working on creating
  the next block in the chain, using the hash of the accepted block as
  the previous hash.

  Nodes always consider the longest chain to be the correct one and will
  keep working on extending it. If two nodes broadcast different
  versions of the next block simultaneously, some nodes may receive one
  or the other first. In that case, they work on the first one they
  received, but save the other branch in case it becomes longer. The tie
  will be broken when the next block is found and one branch becomes
  longer; the nodes that were working on the other branch will then
  switch to the longer one branch.
  Also to prevent double spend it creates a DB of Unspent Bitcoin and validates every transaction based on that.How is a transaction verified

If a block is mined on top of block A (let's call it block C), when Node B hears about block C, it will change its blockchain state to have block C as its tip and block B will become orphaned. This is because block C's chain has more work than block B's chain.

Seeing a double spend in blocks as you describe it does not make a block invalid. If I see a conflicting transaction in block A and block B, that conflict does not make one of those blocks invalid to me.


Can I spend my bitcoin without knowing how to get into my bitcoin wallet? Any advice would be greatly appreciated.

I bought bitcoin about 2 years ago. Put it in coinbase wallet. I have the lost my ability to log in and cannot remember my old phone# to reopen the wallet. I DO have my "share code #" for the bitcoin and I DO have the "Long"#.

Am I out of luck to get access to my bitcoin or is there another way to spend it or transfer it because I have the 2 different codes?

Can I spend my bitcoin without knowing how to get into my bitcoin wallet?

Please give me feedback THANKS!

Technically the Bitcoin can only be spent if you have the private key for the address. The private key is stored in a wallet. If you do not have access to that wallet then you will not be able to spend the money.

Try to contact the customer service of CoinBase to see what you can do with the information you have, also tell them if you have made any backups or wrote down any initial parameters (do not give away the exact parameters as it might be used to recover your wallet, just the fact that you have it or not).

Update:

In the comment below you mentioned they told you to never tell anyone the "Long"# you received, this is good, it is very likely to be a private key (about 51 random lowercase and uppercase letters and numbers) or some kind of "seed" (English words).

In case of the former you need to download a client and try to import that key. If you have the disk space (133 GB) I suggest using the official Bitcoin Core client, then after the initial synchronization finishes load your private key in the debug window follownig the How do I import a private key into Bitcoin-Qt? question. (Note: you are really likely to need to skip step 5 as your wallet is not encrypted.)

For the latter (if the "Long"# is a "seed") you need to use the same website/software you used when generated it but I really cannot help you out more than directing you to the customer service.


Bitcoin success rate After doing some research on bitcoins and blockchain I have got the following doubts..
1. can I transfer bitcoins only after my transaction appears on the block and what happens if it doesn't appear?
2. The success of my transaction lies in the hands of the miners and not in my control.. yes?

Thanks in advance. Please also suggest relevant websites or material from which I can learn more about it.
Thanks again!

I try to help a bit on the question, there is more than it seems:

1.) transactions are basically a transfer of value from one address to another address. When a transaction is sent to you (to your address), then it should have a confirmation in one block, before you can spend it. The miner basically takes all transactions, verifies them for correctness, and puts them into a block.
If you don't wait for a confirmation: the use case would be like this:

your wallet get's notified, that a transaction has been sent to you, and you don't wait for the confirmation. You try to spend the fund of this tx for s.th. else, send it into the network, and you will remark, it does not get confirmed. This might happen, because the original sender has sent another transaction with the same origin of funds to another address (not yours). So in this case, you would "believe" to have received funds, but you actually don't have the funds. It's a trust issue. In general it is said, that 6 confirmations (after ~1 hour) make it sure, to spend the funds.

2.) You are right, it is not in your control. The miners make sure, that the network is working correctly, and security is kept to the highest level. So they provide a service, and get payed as incentive with block rewards and fees.


What is the benefit of using a Merkle Root rather than simply hashing all of the transactions in the block? I understand what the merkle root is and how it is calculated, but I have not been able to figure out what is the actual purpose behind using this kind of hashing solution?

I mean, I know that the root itself must be there, to identify the exact block's payload, but what I don't get is why didn't he just choose to calculate the hash using a normal double SHA256 over the entire block's transactions? Why did he come out with this tree-idea instead?

I do not see the tree based hashing to be adding any security, neither to have any useful advantages over a regular (linear) hash... so am I missing something?

The Merkle tree allows verifying that a transaction exists in the block without having the entire block, by following its Merkle branch. Among other things this enables:

SPV (lightweight) clients
Blockchain pruning
Smart pool miners


What happens when you close a payment channel on tumblebit? When you close a payment channel using tumblebit, what happens?
Is the channel that you close always between you and only one other?
Is the channel between you and any number of accounts/addresses?

Thanks

All the parties who wish to pay have at least one payment channel to the Tumbler (i.e. the payment hub), all parties that wish to accept payments have a payment channel from the Tumbler to them. Thus, each payment channel is either from the user to the Tumbler or from the Tumbler to the user.


getrawtransaction is error bitcoin core I use VPS centos 7, and i install bitcoind follow:
https://www.ringingliberty.com/bitcoin/

this is file bitcoin.conf:

rpcuser=bitcoinrpc
rpcpassword=My_password
daemon=1
rpctimeout=30
rpcport=8332
gen=0
txindex=1
keypool=100

Then i ran: bitcoind -reindex -deamon then ran:
bitcoin-cli getrawtransaction string_txid

i get error:

error code: -5
error message:
No information available about transaction

I use: Bitcoin Core Daemon version v0.13.0.0-ga402396

I don't know wrong?

That will success when bitcoind download all blockchain.

Wait till bitcoind complete synchronization then try again.


Are BTC and Bitcoin Core the same? I recently saw an offer to "Buy Bitcoin Core with your credit card".
Is this "Bitcoin Core" the same thing as BTC?

Kind of. People who call Bitcoin "Bitcoin Core" are referring to Bitcoin. They will also use the name "Bitcoin Legacy". but calling Bitcoin "Bitcoin Core" or "Bitcoin Legacy" is misleading.

Bitcoin Core is the reference client for Bitcoin. But it is wrong and misleading to call a coin by the name of its reference client. For example, we don't call Bitcoin Cash "Bitcoin ABC" even though its reference client is Bitcoin ABC. Nor do we call Ethererum "geth" even though its reference client is Geth.


Timer-based consensus algorithm in blockchain Assume that there is an algorithm that ensures:
1- That a full node chooses an honest random wait time.
2- That the same node has waited the specified amount of time before proceeding to mine a block.

Would there be any need for mining using PoW and Why?
Note that I said an algorithm and not a central entity like  Intel Software Guard Extensions (SGX).

Keeping block time at 10 minutes is only one of the many benefits that PoW provides. Other important ones include preventing double spending and transaction censorship. Most of the PoW alternative consensus mechanisms out there simply fail to ensure this level of security. There is an interesting conversation on the Bitcoin mailing list that dives into Proof-of-Stake and its inefficiencies in ensuring the above.

Double Spending: PoW ensures that a node has spent electricity and compute power in order to find a hash that matches the current target. This ensures that there is a cost involved in case any one wants to 'rewind' the blocks and make a separate transaction that double spends the previous one. This would also mean, that the person who wants to double spend would need to amass more hash power (and hence investment) than rest of the network combined, an almost impossible feat.

Transaction censorship: In cases where you do not have PoW, an attacker will bootstrap millions of nodes to ensure that he is the one that gets chosen to form the block. In that scenario, he can ensure that certain transactions do not enter the blockchain, aka censorship. Censorship attacks cannot be prevented except by ensuring that no single entity can claim 51% control of new block creation. By ensuring this, we can ensure that at least some other entities are unlikely to keep a transaction out of the blockchain, and in particular that no entity can make a short-ranged history rewrite if a censored transaction does get into the blockchain from the efforts of another block producer. This is trivial under proof-of-work, and is ensured by asking people to make huge investment to get the hash power needed to mine block. Since it is non-trivial to acquire energy PoW prevents censorship attacks.


how to fix Bitcoin core 14.2 on Windows 10 Home 64bit ver. I cant install Bitcoin Core 13.2 thru 15.01 64 bit on my window 10 64 bit system it worked ver 14.2 worked before I tried to sign into coinbase that emailed me an address that needed to Identify my computer by clicking it. I clicked it to complete the authentication process. I had a problem with coinbase in the past and they closed my account when I tried to open another account they refused and closed my account again and sent me a message to close my account by clicking the box. since then I've been unable to open my bitcoin core wallet ver 14.2 I keep get this message
and the this when I hit OK
 I've tryed installing versions 13.0 thru 15.1 64bit then 32bit and alway the same thing when I click this OK the wallet shuts down!
I even went as far as installing Bitcoincore for Linux Mint 18.2 and it works great! BUT! I cant retrieve my Backed up wallet and coins from the windows wallet.dat. I'm at my wits end is there a Dev out their or on this site that can help me install Bitcore Core 14.2 (where I had my coins stored) on my Windows 10 Home PC?

first method (if the 2nd method completely wont work):
Go the C:\Users\%USERNAME&\AppData\Roaming\Bitcoin\blocks

(no need to edit the username part)

and then delete everything in it

OR

second method (recommended and faster):
Start the bitcoin core using -rebuild or -reindex flag


can i update my bitcoin qt 0.7 to 0.11 if my wallet has never synchronised and i'm still waiting to receive my bitcoins can some one please give me some solid advice as i am in need of my coins and it seems this is the best way to retrieve my coins but i cant risk losing my bitcoins! i have tried to create a raw transaction to my new multibit HD but cant get the command right!!!! as my IT literate nephew said that is an advanced way to go about it specialy since i know FA about IT work! lol. apparently updating my wallet can solve the slow synchronization. i have version 0.7 but wish to update to 0.11 or 0.10. will this work? how do i go about it? is there a high risk of losing my bitcoins? cheers :-)

Yes, you can update from 0.7.* straight to 0.11.0 without problem. 0.7 is actually incapable of synchronizing with the network due to its age, so the upgrade is mandatory. When you open the new software it will rebuild the files on disk, and then resume synchronization (significantly faster than it was before). There is near zero chance of you losing your BTC by doing this, but make a backup of your wallet.dat file regardless just to be as safe as possible.


Where to find logarithmic graph of Bitcoin over time? I'd like to find a logarithmic graph of the value of BTC vs the simple USD/time graph. Any suggestions of where to find that?

Thank you!

not sure what you mean by logarithmic graph. The time in a logarithmic scale, or the value? On both, there is a "log" button below the graph. And you can export as CSV or JSON:

https://blockchain.info/de/charts/market-price?timespan=all

or alternativly:

https://coinmarketcap.com/currencies/bitcoin/


Does moving funds from one account to another locally require a transaction fee? I am developing a simple wallet with PHP. Right now I don't have the ability to "move" any funds around to test with. I am wondering does the "move" command require a transaction fee?

Answering to the subject of this question:

  Does moving funds from one account to another locally require a transaction fee?

Yes!

If you move(transfer) funds from one wallet to another wallet, there will be a transaction fee for sure.

But,

If you are doing this simply in your server, that is within the website and internal database, then no, there is no transaction fees.

A transaction fee will be levied only if you transfer from one wallet to another in blockchain, not internal to your own database.


Mining calculators and blocks found Whenever we use an online mining calculator, do these calculator estimate a 100% blocks finding? Shouldn't they be subject to the pool efficiency and how many blocks are found? I mean, if my pool only catches 50% of total blocks my mining earnings are cut in half. Is this right?

No, your earnings are related to how much hashing power you contribute to the network, not your share of the pool's hashing power.

Said differently, if you were mining solo and providing an infinite amount of time, the earnings would be the same (minus the fees). Pools only exist to give you more frequent, smaller revenue.


If a wallet has multiple addresses, is the money in the wallet or in the address? In the standard bitcoin client (Bitcoin-Qt), they tell me the total money in the wallet. However, should I be able to see how much money is in each address?

Does bitcoin money belong to an address or on a wallet?

The bitcoins you received with an address are always associated with that address. The wallet is merely summing up the balances of individual addresses contained in the wallet. You can move addresses between wallets by exporting the private key from one wallet and importing them in another and the bitcoins will show up in the second wallet as well.


Are Ripple IOUs e-Money under European law? It has been confirmed by multiple sources that Bitcoin is not electronic money according to EU Directive 2009/110/EC, mainly because it does not represent "a claim on the issuer" and does not have a "face value". Ripple IOUs however do seem to fit the definition, especially if they are denominated in government currencies. According to many national implementations of the directive, only licensed institutions are allowed to issue electronic money.

Is there any legal investigation on that matter or some expert opinion regarding whether Ripple IOUs are in fact bound by electronic money regulations in the EU?

This all depends on what asset the IOU represents and by extension what it can be used for.

If in the case of USD or EUR etc they are accepted for payment of goods or services by a third party who is not the issuer then they are e-money.

In this case the issuer has to be either authorized or registered as an Electronic Money Institution (EMI).

The key difference between this and a deposit account is that no benefit can be given for holding on to the e-money over time such as interest.

They are redeemable for face value minus any reasonable charges.

Ripple IOUs can also be for bitcoins for example. However since they are not considered legal tender - you cannot pay your taxes in bitcoins for example, they are considered barter or the same as gold. These IOUs are not e-money.

If I were to issue Ripple beer IOUs which could be exchanged in any pub worldwide for a beer these would still not be e-money if they were only exchanged for beer since this is a closed market. I could not use my $50 worth of beer IOUs to buy a book for example. If book stores and other establishments started accepting them at face value then they would become e-money USD.

The UK FCS does a good job of explaining

http://www.fca.org.uk/firms/firm-types/emoney-institutions


What are the units of "difficulty"? In various places, e.g. here and here, there are plots of the "difficulty" of bitcoin mining over time. What exactly is the interpretation of these numbers - in what units are they measured?

My first thought was that the "difficulty" is the number of bits that should be zero in SHA256(block+nonce). But, in this case the difficulty should have been a number between 0 and 255, and these sites show much higher numbers.

My second thought was that SHA256(block+nonce) should be at most 2^256-difficulty. But, in this case it should be an integer, while this link shows that the current difficulty level is not an integer.

So, what exactly the number called "difficulty" represent?

Difficulty is a multiple of the minimum amount of Proof of Work (PoW) any valid block can contain.  In Bitcoin, the minimum difficulty (called difficulty 1) is defined in the code by this byte mask:

consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

That is, a hash must start[*] with 8 hexadecimal zeros.  That's 4 zero bytes, or 32 zero bits.

If you double that difficulty, that's difficulty 2.  Double it again and it's difficulty 4, then 8, then 16.  At difficulty 16, the hash must have at least 8 + 1 = 9 zeros.  Double it again and it's 32, then 64, then 128, then 256.  At difficulty 256, the hash must have a minimum of 8 + 2 zeros.  Et cetra...

As I write this, the current difficulty is 4306949573981.513.  We can see how many minimum zeros that corresponds to by taking its binary log, dividing by the 4 bits that are in in half a byte (one hexadecimal character) and adding the eight zeros from the minimum difficulty:

log2(4306949573981.513) / 4 + 8
= 18.49245089279219

For comparison, here's the most recent block header hash (reformatted into byte pairs for readability).  It has 18 zeros, as expected.  (Note: if you do this experiment at home, note that the hashes are always allowed to have more zeros; they just can't have less.)

0000 0000 0000 0000 0023 bfeb 3a02 1b25 7577 9256 7762 275e b72a d88b 7d50 d7f7

[*] Bitcoin is weird.  We display hashes backwards from most other software, so the zeros that start a block header hash are actually at end if you use any non-Bitcoin software to do the hashing.


What is the command line command in electrum to get my public bitcoin address from my private key? I have a bitcoin private key and I want to get the bitcoin address from it. What is the command in the command line for electrum to extract this address?

There is no cli command that can do this. You can do it via 3 methods:

In the Electrum GUI go to the view menu > show console and switch to the console tab. On the console tab type this:

bitcoin.address_from_private_key("<privkeyhere>")

Then once you have the address clear the console history or your private key will be saved to disk:

window.console.history = []

Another option is to simply import your private key into a new electrum wallet. File > new/restore, enter a unique filename and click next, choose to import addresses or private keys and then follow on-screen instructions for the rest.
OP has clarified that he wants to do this via bash so a third option is to write a custom python script:

#!/usr/bin/python3
from electrum import bitcoin
import sys
print(bitcoin.address_from_private_key(sys.argv[1]))

Put the above in a file and chmod +x it. Then run it with the private key as an argument. Obviously anyone else who runs ps on the same system at the same time will see your private key so this approach is not recommended.


Setting up and running CGMiner on a Raspberry Pi for a Jalapeño I have a BFL Jalapeño miner and a Raspberry Pi and I would like to get the Jalapeño to run off of CGMiner from the Raspberry Pi, however, I am not quite sure how to do this.

Doing some research, I came across this guide: http://dominustemporis.com/2013/06/compiling-cgminer-for-the-raspberry-pi-and-butterflylabs-jalapeno/

I am unable to install most of the prerequisites and Im pretty sure it's because they are no longer available or can't be reached for some other reason. I am running the newest version of Raspbian and I ran apt-get update. How can I get CGMiner to install and run on my Raspberry Pi for my Jalapeño?

I recommend using bfgminer, and so does Butterfly Labs.  Well, I guess they say cgminer will work, too :P.

The 4.10/4.3 branch, as well as the latest/master branch, work especially well with the Jalapeños and the Monarchs.

Build Instructions

sudo apt-get install build-essential autoconf automake libtool pkg-config libcurl4-gnutls-dev   libjansson-dev uthash-dev libncursesw5-dev libudev-dev libusb-1.0-0-dev libevent-dev libmicrohttpd-dev hidapi
git clone https://github.com/luke-jr/bfgminer && cd bfgminer
./autogen.sh
./configure
make
make install

Notes

Once you've gotten it to build and work successfully, take a look at the ./configure options and remove any unnecessary drivers/options for efficiency :D


Bitcoin network resources requirement Supposing we are alone, could it be possible to run the whole bitcoin network and full capacity of it (maximum transaction per second by different peer) on a low end computer, and how can someone verify that ?

As difficulty adjusts automatically, it is indeed possible to run a mostly functional network with the bare minimum hardware required for storage and networking.

Naturally, this network will have next to no protection against a 51% attack, as anyone with a faster computer (or computers) will easily be able to outdo your bare minimum hardware.

Running it would be as simple as setting up a new node with a miner, and making sure it doesn't connect to the existing network - an easy way for that would be to have a new genesis block. You can then mine on this network, and the difficulty will adjust itself so that you have a 10 minute block time.


What are the 3 arguments called in function SHA256? void sha256(struct sha256 *sha, const void *p, size_t size)
{
    struct sha256_ctx ctx;

    sha256_init(&ctx);
    sha256_update(&ctx, p, size);
    sha256_done(&ctx, sha);
}

I'm trying to call this function in c-lightning but I'm confused to what the function arguments are.

Let's disect this function call:

void sha256(struct sha256 *sha, const void *p, size_t size)

First we realize that the return value is void which means the function does not return the sha256 of the data. However we see that the first argument struct sha256 *sha is a pointer to a sha256 struct with the name sha. This suggests that the pointer that we pass to the function will afterwards contain the computed hash.

The second argument const void *p is a constant void pointer. This means that the function does not care about the data type of the data for which it computes the hash and it will not be able to modify the memory to which the pointer points to. This makes sense when we want to compute the hash of some data we don't want this data to be changed. Also computing the hash is a binary operation which is possible on the binary representation of any datatype.

This brings us to the third argument size_t size which is supposed to be the size of the data the second argument points to. I assume there is somewhere a typedef statement defining size_t as an integer. As the second argument is just a pointer to the data struct for which to compute the hash the function needs to know how much memory to process.


MtGox api - keeping track of bids/asks that get cancelled I'm getting started with the mtgox api. I'm primarily using this page to tell me how to use it.

What I've currently got, is I can fetch the depth and then put the bids and asks into 'buckets' (each being a range of price), and can tell you the volume at each bucket.

Now what I want to be able to is keep this updated every second or so.

So I'd need to be keeping track of:

Trades being made (ie Bids/Asks being met).
New Bids/Asks.
Bids/Asks being cancelled.

It appears as if the old version of the api could show the net change at each volume, but this doesn't appear to be the case for the new version.

How would I go about doing this?

Your link to the "old version of the API" is actually going to the streaming API which is still available.  Only the http version was updated and from there it looks difficult to obtain accurate  depth info reliably for precise time periods.

So I'd stick with streaming. Updated much more in real-time for your requirements.

Now they deprecated the depth:volume field but they still have volume_int, which is volume change * 1E8, so you could obtain volume from that:

//js for example
var volume = volume_int * Math.pow(10,-8);

Check out the github samples at the bottom of the wiki page to help get started.  For example, this one


Hosting lightning node and non-custodial In Bitcoin we can have a light wallet where we are connected to a full node, by doing this, we have to trust that the full node is feeding correct information, but at least we can store our keys in the light wallet itself.

I've been looking around for a similar solution in lightning and the closest I found are some lightning wallets which host a node in their clouds and an app which controls the node.

Unlike layer 1, keys are not needed in order to perform transactions, which means that you are not only trusting the information the node is providing, also they could perform transactions without your knowledge.

Am I missing something here? Why are those wallets called non-custodial?

I know you can run a full lightning node on you phone like acinq does, but a safe cloud-based solution would lower the barrier of entry for some users

Unlike layer 1, keys are not needed in order to perform transactions, which means that you are not only trusting the information the node is providing, also they could perform transactions without your knowledge.

Keys are required in lightning. Multiple, in fact.

The lightning node itself is identified by its public key. You need the private key to perform the secure handshake so that you can have encrypted and authenticated communication with peers. You also need the node's private key to sign any gossip information about your node or channels.

On forming channels, you need the private key for an unspent transaction output on the bitcoin network in order to fund the channel.

On operating channels, each channel has a unique funding key which is used to spend the 2-of-2 P2WSH output. You must have the corresponding private key to sign each commitment transaction and also the closing transaction - this must be done once per commitment.


How can wallet software implement automatic channel management for Lightning Network? If I'm building a desktop Bitcoin wallet with Lightning support, and I don't want the user to have to worry about channel management, what's the way to achieve that?

I've seen the autopilot solutions for lnd and c-lightning.

I'm currently experimenting with lnd because it's easy to compile for Windows, macOS, and Linux. But lnd's autopilot doesn't seem to be mature enough. And it's not well documented. So I don't know if I should try to use it?

As for c-lightning, how well does its autopilot work? Well, anyway, because c-lightning is in C and its autopilot is in Python, it'll be a heavy lift for me to include them in my app.

So I'm wondering if there might be a simple temporary workaround. Like, what if I hardcode a list of popular nodes and have the app connect to those? Would that work?

I strongly advice against a fixed list of nodes. This might eventually become outdated. A better solution might be that you run the autopilot on a server and deliver the results to the user via an api. This of course would be a trusted solution. But the lib_autopilot.py which empowers the clightning autopilot plugin is a standalone library that can easily be wrapped into a small webserver (or any server sided application) instead of being used as a clightning plugin on the client side. Also it allows much more configuration and fine tuning than the clightning plugin.

Running it as a server might actually make sense as the computations that are necessary to prepare the autopilot are quite heavy and memory intensive and might not be so great with a bigger lightning network on a client's machine. Also once those computations are done the results can be used to run the autopilot several times at rather low cost making it the perfect candidate for a server side application.

That being said the autopilots are experimental features. Being the author of lib_autopilot.py I am happy you agree that the c Lightning solution might be more mature than the lnd version. But I also want to stress with my increased knowledge about pathfinding and routing that I now have in comparison to one year ago I would create a much different autopilot these days.

Edit: sorry you asked how the c Lightning autopilot works. There is a presentation comparing it with lnd https://youtu.be/N7rlHCnaBf8 and explaining some of the challanges. Again it is one year old - so a bit has changed about what should be said about autopilots but it is a good start anyway


Bitcoin Core 0.13.0 did not have SegWit's activation parameters (they were added in 0.13.1). This means that after SegWit's activation, your full node was not aware of it, and thus did not ask for or verify block witnesses.

Bitcoin Core is a fully validating node, so after upgrading to 0.15 it noticed that blocks were present that were missing witnesses, and as result also didn't have those witnesses validated. As a result, it is rewinding blocks, undoing the effects of those post-SegWit-no-witness blocks back to SegWit's activation point. When that completes, it will start downloading the blocks again (with witness this time), and validating them.


RPC giving error -13 Bitcoin rpc calls giving error

-13: Error: Please enter the wallet passphrase with walletpassphrase first.

Your wallet is locked with a passphrase, first you need to unlock it before executing commands related to private keys using walletpassphrase:

# Unlock the wallet for 60 seconds
$ bitcoin-cli walletpassphrase "my pass phrase" 60

# Some transaction commands ...

# Lock the wallet again (before 60 seconds)
$ bitcoin-cli walletlock


Delete all wallet addresses How can I delete all addresses from my Qt wallet without having to download the blockchain all over again from the scratch? I would like to find a bulk way to do it as there are a few thousand addresses I need to get rid of. These addresses are empty and they only cause significant delays to my interactions with the wallet.

I found a similar question indicating Pywallet (https://bitcointalk.org/index.php?topic=34028.0) as a solution but I have to manually remove each address one by one with it, which is not efficient in my case.

Transfer all funds out of the old wallet.
If on Windows, explore to %APPDATA%\Bitcoin, rename wallet.dat to wallet-old.dat.
On next launch of Bitcoin-QT a new, empty wallet.dat will be created.
This will not require re-downloading the blockchain.
Remember to use Settings, Encrypt Wallet on the new wallet.dat.


Upgrade apt bitcoin-core package I originally set up my bitcoin-core node on Ubuntu 16.04 Xenial using apt.
The ppa:/bitcoin/bitcoin package repository that I used isn't maintained beyond version 0.15.0, so I need a different way to upgrade to the latest version.
Options seem to be to use either snap or compile from source.
Would appreciate any advise on options. I have full blockchain and I don't want to do anything stupid like deleting it.
Right now, everything is in /root/.bitcoin. Ideally, I'd prefer to switch to source compiling, so as not to run into this issue again.

If you have to update your Bitcoin core wallet you can just download the new version and open the new bitcoin-qt file.


Calculating a sum of received bitcoins I have a list of bitcoin addresses provided by a user and I am trying to find out a sum deposited to these addresses. I am using blockexplorer.com API to obtain transactions.

This is a typical API call (for convenience only for one address) my script does. The call supports parameters from and to, these can be used to effectively streamline an entire transaction ledger.

https://blockexplorer.com/api/addrs/1Archive1n2C579dMsAu3iC6tWzuQJz8dN/txs?from=0&to=20

There appears to be no error in my streamlining algorithm, but if I summarize values found in valueIn (which should presumably stand for values sent to an address), the result is completely off when compared to result returned in API call totalReceived.

https://blockexplorer.com/api/addr/1Archive1n2C579dMsAu3iC6tWzuQJz8dN/totalReceived

Why am I getting a totally different results?

Is this a correct way to find out if a certain amount was deposited to address (or addresses)?

Fun fact: blockexplorer.com returns a value of totalReceived that is different from a value returned by blockchain.info.

Transactions can have multiple outputs, and multiple inputs. The valueIn field is the sum of all of the inputs of the transaction, not the amount going toward the address you're interested in.

Instead of summing valueIn, you should make a list of all of the outputs, then filter out the ones that aren't sent to the address you're interested in, then sum those up.

  Fun fact: blockexplorer.com returns a value of totalReceived that is different from a value returned by blockchain.info.

The meaning of 'total received' is not well-defined. For example, if I take money at address A, and send it to address A, has address A "received" money? Different APIs calculate this differently.

Note: I assume you're intentionally not looking to find the balance of the address, which is well-defined.


Which block() method does what? In the main.cpp bitcoin code, there are a few different functions for managing blocks.

ProcessNewBlock()
AcceptBlock()
CheckBlock()
ConnectBlock()
DisconnectBlock()

What is a good summary for what each of these methods do, and the differences between them?

CheckBlock() --> Checks the info inside a block
AcceptBlock() --> Additional checks + write to disk
ProcessNewBlock() --> Calls both of the above and also a function called ActivateBestChain(), which decides whether propagation to the network is warranted, among other things.
ConnectBlock() and DisconnectBlock() Append the block in question to the end of the blockchain (or take it off from there), linking it with the previous block's hash.

Bitcoin needs to be industrial-strength code, so expect to see checks everywhere, for anything that could possibly happen (i.e., >1 coinbase transactions in a block, etc.). Moreover, some database operations are atomic, there are decisions when to propagate new blocks to the network, and to further complicate matters, the source code itself is the best documentation out there (slowly changing though, Andreas' Book is just a start).

Let's start with CheckBlock(), which is called by other functions:

Its sequence of operations/function calls are:

CheckBlockHeader() --> checks mostly that the PoW is there;
fCheckMerkleRoot --> checks correctness of Merkle Root & that there are no duplicate transactions
Checks size of the block, whether 1st transaction is coinbase, whether there are other (obviously invalid) coinbase transactions, and only then it checks the transactions and whether the maximum number of sig_ops has been surpassed (which prevents 'a "rogue miner" from creating an incredibly-expensive-to-validate block."');

AcceptBlock() will make its own checks and write to disk;

So, in sum, CheckBlock() makes sure that there are no shenanigans within a particular block, AcceptBlock() will write to disk. ProcessNewBlock() calls both CheckBlock() and AcceptBlock(), here's its outline:

Call to CheckBlock(); verifying it's ok;
Call to AcceptBlock(); as you can see from the comment prior to the call, AcceptBlock() will write it to disk;
Calls and Checks whether ActivateBestChain() is successful

This leaves out ConnectBlock() and DisconnectBlock()...

ConnectBlock() and DisconnectBlock() Append the block in question to the end of the blockchain (or take it off from there).  These are complex functions, in my opinion they are ripe for a slow refactoring, but see the final note:

Final note:  I am not a bitcoin-core developer; if one could edit and help out here, I am sure this answer could be considerably improved.   I know one thing, though: the more you study the code, the better your understanding and appreciation of the industrial strength of this magic internet money.


Which private key format is this? I have a paper wallet as an image file, the QR code of the private key gives a base64 encoded string which gives "Salted_(some binary here)" when decoded. What format is this and can I get the private key without a webcam or phone?

Probably encrypted using an OpenSSL-interoperable format. See

https://crypto.stackexchange.com/questions/8776/what-is-u2fsdgvkx1/8777#8777

http://juliusdavies.ca/commons-ssl/pbe.html

The 8 bytes following "Salted_" should be the salt.

Example cmdline to decrypt:

echo 'U2FsdGVkX19qplb9qVDVVEYxH8wjJDGpMS+F4/2pS2c=' | openssl enc -a -d -salt -des3 -pass pass:changeit
Hello World!


Sending payments from an HD wallet I found these two questions very helpful in understanding HD wallets

1) How do hierarchical deterministic wallets work transaction-wise?

2) a few questions about how HD wallet works

However, I'm still not clear how sending payments would work in the case of HD wallet. Assume the following scenario:

derived public key #15 received 1 BTC in one transaction
derived public key #20 received 2 BTC in one transaction

Now that I want to send 2.5 BTC to some address, what is the procedure of doing that? Do I need to do two separate transactions?

Also I found it overall confusing in terms of what are taken care of by the wallet (bitcoin-core, etc) and what should be done by the user. Thus, would appreciate it if anyone can explain the above by highlighting some steps in bitcoin-core for example.

HD wallets are not special when it comes to transactions. Transactions don't care whether the keys involved were derived deterministically or generated randomly.

Think of a wallet split into two parts: the first part (which we will call the key handler) handles the private/public keypairs and creating digital signatures. The second part (which we will call the transaction handler) handles transaction receiving and transaction creation. Suppose the first part has some functions getnewpubkey (returns a new address) and signdatawithpubkey (receives a public key and some piece of data to sign, returns a digital signature).

So there are two different types of key handlers - ones which randomly generate keys and ones which generate them deterministically (aka HD wallets). These two can be used interchangeable with the transaction handler; the transaction handler does the exact same thing and it doesn't care about how the keys are generated. All it needs is to get keys when it needs them, and for the key handler to sign transactions when the transaction handler asks it to.

In your scenario, regardless of whether a HD wallet was used, the transaction handler knows of two transactions that it can spend from. These two transactions were sent to the addresses that correspond to two keys that the transaction handler asked the key handler to provide (i.e. it called getnewpubkey twice).

Now when you want to send, the transaction handler constructs a transaction that has your two received transactions as the inputs. Once it creates the transaction, it sends it to the key handler to sign (so it will call signwithpubkey twice and pass in the same transaction on both calls but one pubkey for the first call and the other pubkey for the second call). Then it takes those signatures and the unsigned transaction, combines them, and produces a final transaction which is then broadcast to the network.

Notice how the transaction handler which actually receives and creates the transaction does not know nor does it care about how the keys were derived. You could have used a key handler that randomly generates keys or one which deterministically generates them; it makes no difference.

  what should be done by the user. Thus, would appreciate it if anyone can explain the above by highlighting some steps in bitcoin-core for example.

The user does not need to do anything. The user clicks the buttons to get a new address when he wants a new address and clicks the buttons to send Bitcoin when he wants to send. Everything (choosing which transactions to use as inputs, creating the transaction, signing the transaction, etc.) is handled by the software. What the user does with transactions does not change whether the keys were randomly or deterministically generated.


What's the point of Bitcoin eaters? I see some bitcoin documentation sites reference dummy addresses like "1bitcoinEaterAddressDontSend32425663" or something made up like that. I'd assume it's just so people reading the docs won't try to "tip" the writer and send to a foobar address that was made up for the sake of example.

That said, I find addresses under this schema that actually have quite a bit of bitcoins in them. Like hundreds of transactions+ and thousands of USD worth (circa 2016 for future readers).

Here is an example (1BitcoinEaterAddressDontSendf59kuE): https://blockchain.info/address/1BitcoinEaterAddressDontSendf59kuE

Who are these people sending money here, what's the point? Can anyone shed some light, lol.

I'd assume it's just so people reading the docs won't try to "tip" the writer and send to a foobar address that was made up for the sake of example

That is correct!

Other than that, there is no other real point at all. These bitcoins are gone forever and no one will ever be able to get them.

However there is some projects or new coins that does Proof-Of-Burning and by sending the bitcoin correctly to the bitcoin eater address you would get corresponding amount in the new cryptocurrency.


When exactly do the transactions get validated? I have some gaps in my understanding to the life cycle of the transaction that I want someone to help me fill them specially with the validation.

What I understand about the life cycle with my questions:

1) Transaction is signed off by the user through the wallet app and broadcasted to the blockchain network.

The question at this step is: does the wallet app perform any kind of transaction validation that requires to check the whole history of the blockchain at this level ?

2) The broadcasted transaction is now sent to many nodes on the network, and these nodes forward/ "propagate" the transactions to other nodes till all the nodes have this transaction in their "pool of unconfirmed transactions" ?

Tell me if I'm getting any part wrong or not in it's right order

3) Each miner will pick some transactions and start the mining (doing the proof of work till finding a correct hash)

At this level when the miner picks the transactions, does he perform a validation of each transaction that requires full scan of the history of the blockchain ?

4) When the miner solves the block, he will broadcast that block along with the hashed value he produced to the blockchain network in the same way the transaction was broadcasted to some nodes and propagated to the rest. Then the nodes will hash the block header to verify whether or not it produces the same hash so they can accept that block.

The question here is: do the nodes perform another validation at all the transactions sent with the block header to verify they are real transactions not fake ones created by the miner who solved the block ?

Does the validations on these transactions require a check against all the history of the blockchain ?

I know how merkle trees hash multiple transactions and that any modification to a transaction's hash will change the merkle root's value, but my question here is how is that helpful ? wouldn't the miner who already faked up any of the transactions have the right merkle root for all the transactions in the block since he is the one who added them in the first place ? My point is how does merkle root help ? what value does it add ? what kind of attack does it prevent ?

The last question is the consensus, from its definition it is that all nodes agree that they are at the same level with the new block. I know the PoW, but how all the nodes check and communicate together to acknowledge that all of them got the same block ?

The question at this step is: does the wallet app perform any kind of transaction validation that requires to check the whole history of the blockchain at this level ?

It depends on the wallet.

In general, a wallet will likely do some validation as a sanity check to ensure that the transaction they create is valid and will be accepted by nodes on the network. They will usually check that the signatures are valid and that the transaction is valid assuming that the previous transactions it spends from are also valid.

Whether those previous transactions are valid are a different story. There are different validation and security models that are employed. But generally, a wallet will only store and recognize a transaction as its when it believes it to be valid. It will then rely on the assumption that it is valid (whether it validated it or has some other means to believe it is valid) so that it does not need to re-validate the transaction later.

  2) The broadcasted transaction is now sent to many nodes on the network, and these nodes forward/ "propagate" the transactions to other nodes till all the nodes have this transaction in their "pool of unconfirmed transactions" ?

That is correct. But at this stage, nodes validate the transaction using the full transaction history before they relay the transaction further onto other peers. Note that they don't re-validate previous transactions nor do they linearly search through the blockchain. Rather they have databases and  indexes which make transaction validation extremely fast.

Additionally, not all nodes need to have the transaction or to have seen the transaction. There is also no way to know whether all nodes have seen and validated a particular transaction.

  The question here is: do the nodes perform another validation at all the transactions sent with the block header to verify they are real transactions not fake ones created by the miner who solved the block ?

Naively (and previously), yes. A simple implementation would simply re-validate every single transaction received in a block.

A faster implementation (and what Bitcoin Core does now), is to cache whether a particular transaction has been validated before and whether it was valid. So when it goes through a block, instead of re-validating all the transactions that the node has seen before, it just calls up the validation result previously. This can be easily done by restricting the mempool (pool of unconfirmed transactions) to transactions that would be valid if they are included in he next block. So if a transaction that is received in a block is found in the mempool, then it is known to be valid and does not need to be re-validated.

  I know how merkle trees hash multiple transactions and that any modification to a transaction's hash will change the merkle root's value, but my question here is how is that helpful ? wouldn't the miner who already faked up any of the transactions have the right merkle root for all the transactions in the block since he is the one who added them in the first place ? My point is how does merkle root help ? what value does it add ? what kind of attack does it prevent ?

The merkle root has nothing to do with transaction validity.

The merkle serves two purposes: to ensure that all transactions are included in the block hash, and to prove that a particular transaction was in a block without needing the block itself.

Since the merkle root is part of the block header, and since it is the hash of all transactions in a block, it serves to commit all of those transactions to the block header and to the Proof of Work. It just ensures that the block hash covers the transactions as well.

The merkle tree used to produce the merkle root also means that anyone with a full block can produce a simple proof that a transaction was included in a particular block. This is useful for SPV wallets. It does not prove that a transaction is valid and has no effect on whether a transaction is valid. A miner could include an invalid transaction and it would be part of the merkle tree. This doesn't make that transaction valid, nor does it make the block valid.

  The last question is the consensus, from its definition it is that all nodes agree that they are at the same level with the new block. I know the PoW, but how all the nodes check and communicate together to acknowledge that all of them got the same block ?

They don't; there is no need to. Consensus is reached because nodes are connected to each other and broadcast blocks to each other. Because every node is programmed to follow the blockchain with the most work and to do its best to ensure that its peers learn about what it thinks is the best blockchain, the network naturally achieves consensus without any sort of agreement and acknowledgment. By relying on nodes switching to use the valid blockchain with the most work, nodes will converge onto the same blockchain as eventually, one blockchain will have the most work.


How to create an application which constructs a transaction using `bcoin` (javascript)? I am new to development. I am working on a project and I am trying to use bcoin.
I want to create an application which has a UI, where the user will be asked to enter Destination address and amount. And maybe the sender's public key as well, if it is not already entered.
Then the application will fetch the UTXOs relevant to the sender's public key from some other Full Node.
And based the UTXOs and the input data entered by the user, my application will construct a transaction HEX.
I need the final outcome in XDR format. But I will try to do that on my own.

I will not be connecting to the Bitcoin network, I will connect with another network which has forked bitcoin code.
I know this is a very silly question. But if anyone could guide me towards the right path on how to accomplish the above.

This is a very complicated question. bcoin already has a built-in wallet that can do all of these operations for you. There is a well-documented RESTful HTTP API you can read through here: http://bcoin.io/api-docs/ to get an idea of what's available. You can also write your own wallet application using the bcoin object classes directly.

Very broadly however, here's some tips that might interest you:

Enable Address indexing. This is a feature that is not currently available in bitcoind yet (so far I think only indexing by transaction ID is supported). This is switched on with indexAddress: true in bcoin.conf or --index-address on the command line. The address index will enable you to request the transactions associated with a specific address: http://bcoin.io/api-docs/#get-tx-by-address
You will want to process that transaction data and maybe cross-check the UTXO set (so you know what has been spent already) with the API call http://bcoin.io/api-docs/#get-coin-by-outpoint
Check out the MTX and Coin objects to construct a transaction from the UTXO you recover. We have several guides on transaction handling, maybe read through this: http://bcoin.io/guides/working-with-txs.html
Signing transactions with private keys: I'm not sure how your application will work but it sounds like the users will have to sign the TX themselves?

I recomend you read through the bcoin API docs and the guides (and of course, the codebase!). And just focus on the default wallet process for coin selection, transaction composition, signing, and private key handling.


How to get all addresses - including the "change" addresses - from bitcoind? I want to get all my addresses - including the auto-generated "change" addresses - from a running bitcoind somehow.

I haven't been able to do it in a simple way. "getaddressesbyaccount" and all the other API options are only listing the "public" addresses and sometimes few additional ones, but never the already used change addresses. Can I do that somehow?

listaddressgroupings

I used the command listaddressgroupings from the bitcoin-qt console window and it listed all my addresses.  I then looked for one of my old send transactions here:

https://blockchain.info/

And found the change address.  It matches one of the addresses in the list.


Why should BIP157 compact filters be processed in-order? In BIP157, under "Client Operation", we have the following paragraph:

Starting from the first block in the desired range, the client now MAY download the filters. The client SHOULD test that each filter links to its corresponding filter header and ban peers that send incorrect filters. The client MAY download multiple filters at once to increase throughput, though it SHOULD test the filters sequentially. [...]

I'm wondering about the bolded part: why should the client test the filters in sequence? Why can't it test them as it receives them? I'm having a hard time coming up with a good reason to test them sequentially. Anyone knows?

A HD wallet doesn’t know what indexes of a seed to scan for until the ones prior have been used, which can’t be discovered out of order. To allow for out of order scanning the address gap limit would need to be prohibitively large, and might still result in re-scanning filters if the wallet is particularly active.


How can I claim my BCH if my BTC is held with Block.io, a multisig address? Title is enough, but to elaborate, I've been trying to do this for a long time with no avail, I am trying to cash out my BCH, but first I need to acquire it.

There is a solution. I've got my BCH today from block.io which was already empty but it had a BTC on the day of fork.
So what you have to do is:

First of all you should get from security settings of you block.io profile: "Redeem Script Hex", and two private keys. (actually you will have some more strings and values but only these three required to claim your BCH.

After that:

Go to http://www.motelmaya.com/BCH/BCH.html

I know this seems strange and may cause doubts and believe me I wasn't sure too. But the real deal was: getting BCH (I had 0,5 of BTC at block.io wallet) or getting nothing.

So, then:

Click +TX or New -> Transaction.
Enter the redeem HEX that you received from block.io in the first box (Address, WIF key or Redeem Script)
Click on "Advanced options" -> "Network" -> Settings and change the network to "Bitcoin Cash (mainnet)"
Click New -> Transaction once more.
Put in the amount you want to transfer and the address you are sending to (your new BCH wallet I guess - I've used my blockchain.info wallet address), make sure that the fee is not too high (I've entered something like 0.000317
Click "Submit", you will get a long HEX string. copy it
Click "Sign", paste the copied string, paste the first private key from the  block.io to the "Private key" field, click "Submit", copy the string.
Paste the string into the second box (below the "Private key" field), paste the second private key from the block.io, click Submit, copy the output
Go to "Broadcast", paste the string and click "Submit".

That's it. You will recieve TXid which you will be able to check at https://bitcoincash.blockexplorer.com

Actually all regards should go to ohad serfaty but I can't comment the post where he advised this method because of low reputation.

Good luck!


Since there is a limited number of bitcoins, will miners become obsolete? The way i understand it, by calculating and validating new blocks miners keep the bitcoin network safe. As a 'reward' for this they recieve bitcoins.

However, since the number of bitcoins is limited, will there be a point where mining is no longer useful, because there is nothing left to mine? And if so, who will keep the chain safe?

It is an frequently occurring but incorrect assumption that the purpose of mining is creating bitcoins. The reason mining exists, is finding blocks, so that a global consensus about the order of valid transactions can be established. Mining is hard because we don't want too frequent blocks.

One of the very original ideas in Bitcoin is combining this block construction consensus mechanism with the initial introduction of new currency, but it could have been done in very different ways.

So, even when the block subsidy dwindles and eventually becomes zero, mining will continue. Blocks will still be needed and if miners don't create them, other miners will pop up. They are expected to be paid from transaction fees.


Found my Multibit.key wallet back up, but I do not remember the password, what next? I created a Multibit wallet back up many years ago and it was saved as multibit.key.
I am now trying to import this back into MultiBit Classic and it is asking for a password. I have forgotten the password.

Is there anything I can try? Is brute forcing an option? What type of software would I have to use?

Cheers

You can try using btcrecover to attempt to brute force your password. However, if you have no idea what the password could be, then it isn't going to be able to help much.


why can I not recreate my blockchain.info addresses? I'm trying to generate a list of all my Addresses ever used on blockchain.info wallet with balances prior to august 1st,2017. i used the tool below to do this:
https://github.com/iancoleman/bip39
But when I feed this with my Twelve word backup phrased from blockchain wallet, It does not work and gives the error "one word is not listed in dictionary!"
what's the issue? what should i do?

I solved the issue! the point was that in fact I should have removed 1. , 2. etc before my 12 word seed phrase.pretty funny, huh? :)


How to prevent a miner from stealing another miner's block? Many articles only contain a phrasing like

  A miner A solves the hash problem and gives the result to the network to check. Once a majority of the network confirms, A gets the reward.

But how does one protect his effort from being stolen? As I think:

A solved the problem, so A get original string S which could be hashed to target hash H.
A sends his result to the network (some other miners) intending to get the reward.
Other nodes (miners) need to hash S and check whether the result equal to H to determine whether A is right or not. (So I think here one can get S and H)
But B near A, he get A's works, so he get the S and H. Then he can construct a new result send to others, claim that B solved the problem
If B can spread his result faster than A, he gets the reward.

I have seen Can a miner steal another one's block? , in which @Highly Irregular says

  The block that Alice mined includes the mining rewards going to
  Alice's address. If Eve alters the block data to output the rewards to
  her own receiving address, then the nonce (and other variable values,
  I think "extranonce" and timestamp) that Alice used to solve the block
  will almost certainly no longer solve the block.

But he didn't tell how in detail.

@Stéphane Gimenez gave the normal steps of mining here, in which I didn't see a measure to prevent B from stealing the block from A (or how to validate the result is originally calculated by A).

A is protected by adding coinbase transaction with himself's bitcoin address.

from https://en.bitcoin.it/wiki/Block_hashing_algorithm

The body of the block contains the transactions. These are hashed only indirectly through the Merkle root. Because transactions aren't hashed directly, hashing a block with 1 transaction takes exactly the same amount of effort as hashing a block with 10,000 transactions.

The compact format of target is a special kind of floating-point encoding using 3 bytes mantissa, the leading byte as exponent (where only the 5 lowest bits are used) and its base is 256. Most of these fields will be the same for all users. There might be some minor variation in the timestamps. The nonce will usually be different, but it increases in a strictly linear way. "Nonce" starts at 0 and is incremented for each hash. Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.

Moreover, it is extremely unlikely for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of your unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.

Another expalatation from http://www.righto.com/2014/02/bitcoin-mining-hard-way-algorithms.html

The diagram below shows the structure of a specific block, and how it is hashed. The yellow part is the block header, and it is followed by the transactions that go into the block. The first transaction is the special coinbase transaction that grants the mining reward to the miner. The remaining transactions are standard Bitcoin transactions moving bitcoins around. If the hash of the header starts with enough zeros[3], the block is successfully mined. For the block below, the hash is successful: 0000000000000000e067a478024addfecdc93628978aa52d91fabd4292982a50 and the block became block #286819 in the blockchain.

Structure of a Bitcoin block


Compile vanitygen source How do I compile this source or get vanitygen for linux?

Open source link:
https://github.com/samr7/vanitygen

I would suggest you use Bitaddress.org

its open source and secure without the need to install anything.

or you could do that using bitcoin-php library on PHP.

vanitygen is too old and never updated almost since 7 years.

UPDATE

Sorry for the previous suggestion, I thought bitaddress.org has that function.

vanitygen library that you mentioned is too old, you better use
vanitygen-plus, it's up-to-date and supports bitcoin and alt-coins.