How to get new address on bitcoin core through extended public key i am going to lunch a new service for merchants to use my service API to receive payments directly in their wallets through xpub key , now i have installed bitcoin core is this possible with bitcoin core or i need as well electrum server

<?php
    //replace with your BIP32 extended public key
    $xpub = "xpub661MyMwAqRbcGTFHLp4c7j2hByE3qAZdN37FqJHTAmSPE2vfL4GAQ4mZvGZz4bVzpfdwoeoEBXWV5g2vWwP";
    $url = "https://api.smartbit.com.au/v1/blockchain/address/".$xpub;
    $fgc = json_decode(file_get_contents($url), true);
    $next = $fgc["address"]["extkey_next_receiving_address"];
    ?>

    <!DOCTYPE html>

<?php echo $next;?>

    <?php

    Print_r($fgc);
    ?>

There are php libraries that you can use. For example the ones in my plugin bitcoin address in the includes/libs directory. These libraries were originally created by the authors of the bitcoin payments for woocommerce plugin.

There is also the bitwasp php library but it is a lot larger and does more things than merely deriving addresses from xpubs.


Is the Cloudflare proposed ODOH protocol a thing that could improve Bitcoin node privacy? Recently Cloudflare proposed an improvement to the DNS over HTTPS protocol called ODOH (Oblivious DNS over HTTPS). It allows separating a DNS server into two parts: the resolver and the proxy that receives DNS requests from an end-user, thus avoiding leaking an IP address to the resolver and an actual query to the proxy server.
When running the Bitcoin node with the onlynet=onion parameter, one has to either leave DNS queries enabled (which could potentially reveal a user is running Bitcoin), either to disable the DNS queries completely (dnsseed=0 and dns=0), and then to seed some good nodes with the addnode= parameter.  Both options aren't perfect.
Does (hypothetically) using the ODOH protocol for the initial node discovery make any sense from the privacy perspective?

Bitcoin running with onlynet=onion is severely insecure, nobody should ever be running the software in this mode. There is no sybil protection, it is completely feasible to operate an unlimited number of HS peers and prevent a node from ever connecting to one which will give them a true vision of network consensus. There is no cost to performing this attack whatsoever.

one has to either leave DNS queries enabled (which could potentially reveal a user is running Bitcoin)

DNS queries can be proxied as well.

Does (hypothetically) using the ODOH protocol for the initial node discovery make any sense from the privacy perspective?

I doubt it makes any meaningful difference, especially as seeding is typically only something which happens for initial startup of a node and likely never again. You're almost never going to be able to hide that you're running a Bitcoin node from your ISP, even by using a proxy the traffic patterns are very obviously Bitcoin.


What does an orphaned tx look like via rpc? I am testing with a currency forked from Pivx, but I see that bitcoind responds the same way here https://bitcointalk.org/index.php?topic=100824.0 with error code -5
If I send/receive a tx that then some time after a few confirmations (the block) was to become orphaned or stale; Would I get the same reply from rpc gettransactions as below (where I intentionally typed a non transaction id in) if I were to look for the tx or should it come back with a full tx object?
zdx-cli gettransaction "gyyyyf"
error: {"code":-5,"message":"Invalid or non-wallet transaction id"}

There are two cases here:

Block with the tx became orphaned and the transaction is still valid. In this case it is returned to the mempool. gettransaction will return unconfirmed transaction detail
Another conflicting transaction got confirmed ( having same inputs). In this case existing txid becomes invalid and it is discarded


Check txout against the circulating supply instread of MAX_MONEY https://github.com/bitcoin/bitcoin/blob/aaaaad6ac95b402fe18d019d67897ced6b316ee0/src/consensus/tx_check.cpp#L27

If txout.nValue is more than the circulating supply and less than MAX_MONEY, CheckTransaction would return true.

Why not check txout.nValue against the circulating supply? and if it is above then just return false at that point.

There is no point. It would just be slower and more complex for no gain.

Despite what the name may imply, that test is not there to enforce the inflation schedule. It's there to prevent exploiting integer overflow (something which happened in Bitcoin's early history).

The test could be replaced with > 1000000000000000000 instead and be equally effective.


What is the store that sells the famous alpaca socks for Bitcoin? In the now-sort-of-viral Bitcoin video, one notable mention of Bitcoin use was to buy alpaca socks. What is the store that sells or used to sell those iconic socks for Bitcoin?

That would be Grass Hill Alpacas at http://www.grasshillalpacas.com/
From their website:

Grass Hill Alpacas is located on 115 acres that has been in the family for over 125 years. The farm is located at the foot of Grass Hill in the Haydenville section of the town of Williamsburg, just 10 minutes from the center of Northampton. The last time the land was actively farmed was in the 70's, when the last of Stanley "Stubby" Nash’s oxen were sold. Currently our operations are based on 5 acres of old pasture land that we have reclaimed and fenced in. With more than 40 acres of fields, we have plenty of room for expansion as needed.
We brought our first 6 alpacas onto the farm in the summer of 2006. It has been an exciting, rewarding time for our family and our farm. We have learned alot, had some great experiences and built wonderful new friendships that will last a lifetime. But the best part of it all is that we did it together as a family...side-by-side... working the same land that great-great-grampie worked.

Also, don't forget this song about the famous alpaca socks:
Max Min - Alpaca Socks (Official Music Video)


How to know the destination address of a multisig? Run this command:
bitcoin-cli getrawtransaction 56214420a7c4dcc4832944298d169a75e93acf9721f00656b2ee0e4d194f9970 2
You will see the first vout is a multisig as follow:
 {
      "value": 0.04030000,
      "n": 0,
      "scriptPubKey": {
        "asm": "2 02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242 033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d 036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a 3 OP_CHECKMULTISIG",
        "hex": "522102c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb92624221033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d21036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a53ae",
        "reqSigs": 2,
        "type": "multisig",
        "addresses": [
          "1PfTD843HiN2PPpxFnMwyxN7se6MEf2ech",
          "1JXc8zsSeAPwqfAzLbBnZxNTfetZexH2bW",
          "1Ng4YU2e2H3E86syX2qrsmD9opBHZ42vCF"
        ]
      }
 },

And from bitinfochart, we can see the destination address is not

1PfTD843HiN2PPpxFnMwyxN7se6MEf2ech
1JXc8zsSeAPwqfAzLbBnZxNTfetZexH2bW
1Ng4YU2e2H3E86syX2qrsmD9opBHZ42vCF

but 3844dWM7n5c1oAYhtQc5uLtKB6TjN5PSW4
Can someone tell me how to get the destination address, 3844dWM7n5c1oAYhtQc5uLtKB6TjN5PSW4?

The website displays the scriptPubKey of the first output as if it was a P2SH (more commonly used for multisig), but it's not.
This is a bare multisig. As another explorer example, Esplora displays it more accurately (there is no address for this Script type).
The addresses field of getrawtransaction (and a few other commands) output will for bare multisig outputs give you the P2PKH address of each of the key used in the multisig.


Testnet peers list (with IP addresses) There are some services to get the list of current known peers,
like those offered by 21.co or Blockchain.info
but I can't find anything similar for the Testnet network.

Does anybody know a Testnet peer list?

Actually, it is also very hard to find any IP testnet address.
Is there a reason for that?

Just use a testnet dns seeder.

Type this into your terminal:

dig A testnet-seed.bitcoin.jonasschnelli.ch

or

dig A seed.tbtc.petertodd.org

for IPv6

dig AAAA testnet-seed.bitcoin.jonasschnelli.ch


Share the same private key on two ledger devices I have 2 ledger device.

Let's suppose one for me and one for my wife.

We want to share the same bitcoin account.

Is it a good practice to setup the first ledger and then restore the keywords on the second ledger (while the first is still working) ?

Thanks

Whether or not it is good practice depends on your threat model (I personally wouldn't for security reasons), but it is technically possible - the ledger devices and corresponding computer apps will have no issues with it.


Using Armory Watch-Only wallet in Electrum? Is it possible to import a Watch-Only wallet that was made in Armory into Electrum?

I like to use Armory for cold storage but like Electrum more for hot wallets because it's lightweight and you never have to sync. Is there a way I can import my cold storage wallet's watch-only copy that was made with Armory into Electrum on my personal computer?


Who checks if the entire chain in valid? How can we be sure that the entire chain is valid?

1- I read somewhere that one of the purposes of blockchain is that you can't change the blocks of the past without recomputing the entire thing. Is that assumption correct?

So if you could hypothetically recompute everything, you could generate a new chain. I also read somewhere about some problems that Proof of Work try to solve and there was this possibility of a concurrent plausible solid chain.  How is that possible? Who can generate an entire chain?

I explain my doubt:

2- Miner will find a nonce, giving a block data, to generate a hash that matches a certain difficulty. Is that correct?

So the miner knows a new block. But not the entire chain. 3- Does it? So when it finds the nonce and hash it announces a new block to a different kind of node, let's say the full node (what is that exactly?).

4- Where in the flow and by whom in the network the entire chain will be exchanged so they need to decide which chain is better?

5- By the way, what is the best chain given two versions of them?

extra:
6- ok, the blocks are correct and the chain is valid everybody agrees with that. Who in the network checked if A that passed 1btc to B had 1btc to perform this action?

Please could you clarify 1, 2, 3, 4, 5 and 6?

1- I read somewhere that one of the purposes of blockchain is that you can't change the blocks of the past without recomputing the entire thing. Is that assumption correct?

Yes, that is correct. Each block builds upon (references) the one before it, so changing one in the past would require you to update (recompute) every block since then.

  2- Miner will find a nonce, giving a block data, to generate a hash that matches a certain difficulty. Is that correct?

Yes, a miner will vary the nonce/extra-nonce/transaction order/etc, until a valid block hash is found.

  3- So the miner knows a new block. But not the entire chain.

Incorrect. The valid block hash that the miner finds includes a reference to the prior block's hash. So in effect, the miner knows about the new block, and the entire chain before it, since all prior blocks are linked by their block hashes in this way. Each full node (which includes miners) will store a record of the blockchain so they can reference all new blocks and transactions against the blockchain history.

  4- Where in the flow and by whom in the network the entire chain will be exchanged so they need to decide which chain is better?

The longest valid chain is what the network's nodes will follow, which in practice means the valid chain with the highest accumulated proof of work.

  5- By the way, what is the best chain given two versions of them?

If two valid blocks with the same block height are found, whichever one is built upon first will be the winner. Please look up info on 'orphan blocks' to learn more about how this plays out.

  6- ok, the blocks are correct and the chain is valid everybody agrees with that. Who in the network checked if A that passed 1btc to B had 1btc to perform this action?

Each full nodes will check to ensure that all new transactions and blocks are valid, and they will ignore any that are invalid. Each node keeps track of where all of the bitcoins are located, a blockchain system has extreme redundancy. A full node operator can tailor their node to only store/relay certain types of information if they so desire, but all of the info


Can't make successful call via remote JSON RPC I can verify that my node is up and that the port is up via the above method, however no amount of effort has allowed me to successfully make a remote RPC call.

I am booting my node via $ bitcoind -daemon

I can make RPC calls via the same server without an issue using $ bitcoin-cli getinfo

My bitcoin.conf file looks like:

rpcuser=rpcuser
rpcpassword=anthony
rpcallowip=::/0

I have also tried:

rpcuser=notmyrealuser
rpcpassword=notmyrealpass
rpcallowip=0.0.0.0/

Without luck, both of which were suggested here: https://github.com/bitcoin/bitcoin/issues/4894 by the lead Bitcoin engineer.

I am trying to authenticate using curl, the two scripts I am using are:

curl --user notmyrealuser --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }'  -H 'content-type: text/plain;' http://124.223.81.11:8333/

and also:
curl --data-binary
'{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://notmyrealuser:notmyrealpass@104.223.81.11:8333/

Nothing is working so I figured I would ask here after several hours of not making progress, everytime I receive:

curl: (52) Empty reply from server

You're trying to send RPC queries to the P2P network port. You should use port 8332 instead of 8333.

Bitcoin Core:

interacts with other Bitcoin nodes on the network using the P2P protcol via port 8333 (or whatever you configure -port to be)
responds to RPC queries (JSON-RPC) via port 8332 (or whatever you configure -rpcport to be).


Bare minimum system requirements for Core The Bitcoin.org page on Bitcoin Core Requirements and Warnings lists three types of setups:

#
Type
Disk Gb
Gb / mo
RAM Mb
Windows

1
Bare Min (default)
350
8 / 150
512
7/8.x

2
Bare Min (custom)
5
5 / 0.3
256
7/8.x

3
Minimum Recommended
350
15 / 150
1,024
7/8.x/10

I don't think I want to dedicate 1/3 Tb to running Bitcoin Core, so #1 and #3 are impractical, but #2 seems feasible. However, there are two problems with #2:

The download specs for all three types have the footnote, "Plus a one-time 340 GB download the first time you start Bitcoin Core." That seems like a contradiction of the requirement of only 5 Gb of disk space for type #2. So which of the following is correct?

The footnote should not appear in type #2, or
The Disk space spec of 5 Gb is wrong, or
I'm allowed to discard the initial download after starting Core.

The spec says type #2 is not compatible with Windows 10. Is that true?

Summary: For the Bare Minimum (With Custom Settings), i.e., type #2 above:

Is the spec of 5 Gb minimum disk space correct? How is that not a contradiction of the footnote stating a requirement of an initial download of 340 Gb?
Is it compatible with Windows 10, even though that OS is not listed in the spec?

Bare min setup uses the bitcoin's feature called pruning.
In prune mode your node will sync the whole blockchain (the data on the website is a bit outdated, it's closer to 400GB now), but it has to start from block 0. If you set your pruning to 5 GB, it will start syncing from block 0 till the 5GB limit and after that will still sync (so your internet connection has to go through whole 400GB) but will delete older blocks. So at the end your history will be only latest few dozen k blocks. But your node in the process will "parse" all the 400+ GB of data, just keeping latest 5GB at a time.
Yes, bitcoind/bitcoinqt works on windows 10 :)


If ASIC based machines can run at 14TH/s, why isn't the answer found almost immediately? As far I understand correctly, the objective is to find a nonce which creates a hash with the specified difficulty. The current difficulty being around 1.4 trillion. If that is so, why doesn't a machine which runs at 14 TH/s calculate the nonce in under a second?

As explained here in the Bitcoin Wiki, the formula for using the Difficulty to determine the expected time to solve a block is:

time = difficulty * 2**32 / hashrate

Currently, the difficulty is 1,452,839,779,146 so a 14TH/s ASIC miner would be expected to, on average, solve a block with

time = 1,452,839,779,146 * 4,294,967,296 / 14,000,000,000,000

which gives a result of 445707095 seconds, which is about 14 yrs, if I've done my calculations correctly.
To double check that the technique works:
Using the current approx network hashrate (according to blockchain.info) of 10,183,000TH/s, and the same difficulty as indicated above, the formula gives a result of 612s to solve a block, which is the expected result of approx 10 mins.


I keep hearing about MAST, what is it and what does it do? So, somebody asked me about MAST yesterday.

Apparently, it's formalized in BIP114 – Merkelized Abstract Syntax Trees.

I couldn't explain what it was and what advantages it'll bring us.

What are MAST, and how will they help with scaling?

From what I've read and heard about MAST, it's an alternate version of pay-to-script-hash that uses a Merkle root instead of a regular hash digest.  It combines this idea with that of an abstract syntax tree, which is a data structure that compilers use to parse source code.  By "Merkelizing" a syntax tree, it allows redeemers to only expose the parts of the script being used for redemption.

This means that you can have more complicated scripts than are currently allowed by the 10,000 byte or 201 OP code limit.  Let's say there's a redemption script whose conditions look something like this:

A OR (B AND (C OR D)) OR ((E OR F OR (G AND H)) AND NOT I)

Right now, this script would be too complicated to fit inside the limit.  By forming it into a syntax tree and Merkelizing it, a redeeming transaction would only have to expose the conditions that were met.  For example, just A would redeem it, and so would just B and C.  This fits inside the size limit, while also never revealing the unused conditions that could have been used to redeem the UTXO.  There's a complexity gain without introducing the risk of DOS attacks, as well as a privacy gain.

I'm unsure how this will directly help with scaling, but since it allows for more complex scripts without a transaction size increase, it certainly won't hurt.  It's just another building block at the disposal of a developer, which they can then hopefully use to solve some future problem.


Can a testnet node have a separate bitcoin.conf file? When running bitcoind on testnet, can I put its configuration settings in a separate bitcoin.conf file from the "real" bitcoin.conf file?  I would like to be able to run two nodes concurrently, one on the live network and one on the test network, each with its own configuration settings.

By default bitcoind will look for the file bitcoin.conf in its datadir directory, whether running on testnet or mainnet.  But you could use the -conf option when starting one or both of the daemons, to point it to a different file.


Why are there so many confirmations? A friend sent me Bitcoin to my blockchain wallet. It shows the amount as part of my balance. However, it says there are 108 confirmations and the number of confirmations keeps going up. Why is this happening? Can I spend this Bitcoin while confirmations are continuing?

The number of confirmations indicates under how many blocks your transaction is buried. The more the confirmations, the more your transaction is secure from double-spending attacks. So the confirmations will continue growing forever - this is normal behavior.


When was the last time a block was solo-mined? Was curious about it the other day, what would be the quickest way to check for the last block payout minus the transaction fee to know when the last block was solo mined?

Thanks.

It is impossible to know whether a block which has no identifying characteristics (i.e. the miner did not put some sort of signature text in the coinbase) was solo mined or pools mined.

The payout values have nothing to do with solo mining.


bcoin chainldb Resource Temporarily unavailable I'm trying to run a script that retrieves transactions from the blockchain. When I run the script though I get the following error:

Error: IO error: lock /home/bucko/.bcoin/testnet/chain.ldb/LOCK: Resource temporarily unavailable

Here is the JS I'm trying to run:

'use strict';

const path = require('path');
const bcoin = require('../..');
const Chain = bcoin.chain;
const Logger = bcoin.logger;
const util = bcoin.util;

const HOME = process.env.HOME;

// Setup logger to see what's Bcoin doing.
const logger = new Logger({
  level: 'debug'
});

// Create chain for testnet, specify chain directory
const chain = new Chain({
  logger: logger,
  network: 'testnet',
  db: 'leveldb',
  prefix: path.join(HOME, '.bcoin/testnet'),
  indexTX: true,
  indexAddress: true
});

(async () => {
  await logger.open();
  await chain.open();

  const entry = await chain.getEntry(50000);
  console.log('Block at 50k:', entry);

  // eslint-disable-next-line max-len
  const txhash = '7f5990b008a2d0fc006d13b15e25d05ff30fadab656d49a5c6afea0e0d0b458c';
  const txmeta = await chain.db.getMeta(util.revHex(txhash));
  console.log(`Tx with hash ${txhash}:`, txmeta);

})().catch((err) => {
  console.error(err.stack);
  process.exit(1);
});

You must be running testnet in another shell or some other script that has opened the chain database.

Whenever you open chain database it gets locked so only one process is in charge of it.

lsof -d txt | grep filename You could try this one to locate process holding FD for it.


Do miners receive a reward when solving the hash for the next block or when validating the block, or both? Let's say I want to make a transaction to my friend Bob.

When I send 10 BTC to Bob, a transaction is signed with my signature and sent to the network.

What happens next?

Do miners check if this transaction is valid (check if I have enough funds)?

If they do, do they receive a reward for this?

When the transaction is considered valid it gets sent to a block with other transactions.

This block is then mined (miners try to find the correct hash from the previous block by solving the problem) and once a miner solves this first, he sends the block to the blockchain.

My question is, if the block is invalid and gets sent to the blockchain, why other miners check if said block is valid?

Does the first miner that "solved" the block wrong get a reward?

What if the block that was solved by this miner validated correctly and was sent to the blockchain.

Why would other miners check if it's correct when the miner already received the reward.

What do they get from checking the solved block if they are already working on the next one?

I'm sorry for the long post but this part confuses me quite a bit.
Thank you

Do miners check if this transaction is valid (check if I have enough funds)?

Every node that receives the transaction will validate it, this includes the nodes miners run.

  If they do, do they receive a reward for this?

There is no reward for this

  My question is, if the block is invalid and gets sent to the blockchain, why other miners check if said block is valid?

They check it precisely to see if it is invalid. If a broadcasted block is invalid, and a miner starts mining the next block using the invalid block as their previous block, the next block mined by them will also be invalid, since it builds upon an invalid block.

This results in them losing any work invested in finding this new block, since it will be rejected by the network.

  Does the first miner that "solved" the block wrong get a reward?

If the block is invalid (“wrong”), then it will not be added to the blockchain by any other nodes/miners. So they will not get a reward.

For finding a valid block, they receive a certain amount of new Bitcoin + transaction fees (in the coinbase transaction).

  Why would other miners check if it's correct when the miner already received the reward.

If they don't validate it, and it turns out to be incorrect, even if they succeed in finding the next block, they will receive nothing in return since it will be rejected for using an invalid block as the previous block.

  What do they get from checking the solved block if they are already working on the next one?

A guarantee that if they solve the next block, it will not be rejected for building on an invalid block.


How does Proof of Stake prevents dishonest behaviour compared to PoW? I know that in Proof of Work (PoW) once a node has found the solution (the nonce) they announce it to the network. Then the rest of the nodes can easily verify the correctness of the block hash and append it to the chain.

But in case the solution is not correctly verified, the block is finally not appended to the longest chain and therefore the dishonest block is discarded.

I know that in case of PoS, the dishonest node would lose the stake, but,

How does this procedure works in the case of Proof of Stake (PoS)?

I mean how is the validity of a block checked and how the bad node lose the stake?

First of all, proof of stake is not a single algorithm. There are many different implementations. For example, the algorithm that is used in Cardano is completely different from the one that is used in Peercoin, which is quite close but still different from e.g. Blackcoin algorithm, which has been derived from Peercoin. Qtum, for example uses Blackcoin algorithm. And again, all this is very different from what Ethereum plans to do.

So, your question cannot be answered in general. We can only talk about concrete implementations of proof of stake. The largest family of PoS coins is based on Peercoin, but many different modifications have been implemented.

So let's talk specifically about family derived from Peercoin. This includes coins like Qtum, Emercoin, Navcoin, Stratis, NovaCoin, Blackcoin, PIVX, Neblio, ABBC Coin, Particl, ...

As mentioned already, there are many different flavors of the algorithm among these coins. But in general, they work as follows.

They implement a special kind of transaction called coinstake (CS) transaction. This transaction is used to prove that the block was created correctly accordingly to the used PoS protocol. Just as with proof of work, in prove of stake there is the adjustable difficulty and the target that each block needs to satisfy. Just as in Bitcoin, the target is 256 bit number. The coinstake transaction's first input is called kernel. And usually the rule is something like this:

SHA256(SM || PT || KH || KN || T) <= WT

where

SM is StakeModifier - There are several flavours on how this is actually calculated. One example is that SM_n = SHA256(SM_(n-1) || KH), where n is block number (height);
PT is time of the block where the coin (UTXO) used as kernel in CS was created,
KH is prevout hash of the kernel,
KN is orevout N of the kernel,
T is block time,
WT is weighted target, calculated as WT = Target * (value of kernel UTXO).

So if you are PoS block producer, you have wallet with all your coins and what you do is that you periodically check whether one of your coins cannot satisfy the rule above. If you have such a coin, you are allowed to create a block. You can observe that is the time passes, T changes, so you get new and new hashes on the left side with every new coin, so eventually it happens that some coin on the network will pass the rule for the given target.

The longest chain concept is very similar to Bitcoin again. chain work is again sum of block difficulties, and the longest chain is the one with the most chain work. However, due to stake grinding attack, there are limits to the application of the longest chain rule. In some coins, so-called maximal reorganisation length is introduced, in others it is called dynamic checkpoints et cetera. This prevents a node to switch to a better chain if it would need to replace too many blocks from its currently best chain.

There are many other technical details and subtleties, but this is the basic concept. Note that in this family of PoS algorithms, you cannot lose the stake. I'm actually not aware of any finished implementation of PoS in which you could lose your stake. The idea here usually is that rather than taking the stake away from dishonest nodes, the protocol is attempted to be designed in a way that cheating is not possible. However, this attempt is very hard to meet perfectly because of certain properties such as nothing at stake.


How big can a wallet get? Say for an exchange that manages thousands of users, and each transaction needs a new receiving address, how much space would thier wallet(s) take.

I am assuming 100000 users and each user would have about 10000 transactions, so there are about 10^9 keys to be stored. For safety, we would say there are 10^10 keys max that may be stored.

All I need to know is the size of one key stored in the wallet.

The bitcoinj private keys are 32 bytes long. You would also want some sort of indexing around them so that you could access them efficiently.

If you used a deterministic wallet you would only need one seed and a chain code per customer and generate the addresses as required. I think they are typically 32 or 64 bytes long.


Mining: what is the lowest possible target? Could it be a block hash of all zeros? I had a basic question about Bitcoin mining. I understand that as the bitcoin difficulty adjustment becomes harder the hash output will require more 0s in the beginning of the hash. Is it theoretically possible that the Bitcoin difficulty adjustment would be so large that the hash output would just be all 0s? I know this is theoretical bit I'm just curious.

The retargeting every 2016 blocks is computed as follows:

previous_target * (T2-T1) / (20160 minutes)

Where:

T2: timestamp of previous block
T1: timestamp of block at current height - 2016
Target adjustment bounded to factor 4

Ignoring the target adjustment limit: For the resulting target to be zero, T2-T1 would need to equal zero. That would require an infinite amount of hash-rate. Therefore we can approach your scenario, but never reach it.


What software should I use to open the .dat flles I've just downloaded the Bitcoin Core for Windows.

I can see several .dat file. What can I use to open them. i.e. Is there a way to view them in plaintext?

Also, which file is the blockchain file?

Thanks!

The .dat files are opened by Bitcoin Core, they are not supposed to be opened in plaintext. The blockchain will be in the blocks/ subdirectory. You can see a list of the files bitcoin core uses here:
https://github.com/bitcoin/bitcoin/blob/master/doc/files.md


P2Pool Missing BTC Reward in Block History I have been studying the block history for P2Pool here:

http://p2pool.org/stats/?blockoffset=40

over the last several days.  I noticed that bitcoin reward for each recent block is blank until 459871 and previous blocks (which appears after scrolling through several pages of block history).  Once you get to block 459871, it shows mining rewards as I'd expect.  Can someone help me understand why this is?  I have been mining on the site for quite some time with some S9s and still haven't received a reward.  I'm wondering if this might be the cause?

Well there is a message being displayed on the P2Pool site that reads, "January 25, 2018: Our historical block data became corrupted (only relating to it's display on this website), data for all blocks after April 1st, 2017 were lost. They will be restored to the data set ASAP." so this is the reason for the missing information.


How to return BCH with address BTC The COPAY app I have 2 wallet,BTC and BCH. I transferred Cash to Bitcoin address BITCOIN, money stuck so BTC WALLET does not accept BCH how to get the money back or transfer them to BCH WALLET

hopefully this answer helps you.

Specifically,

  There is nothing which distinguishes a BCC address from a BTC address; they are both the same format and refer the the same keys, thus a BCC address is a BTC address and vice versa. This means that if someone sends BTC to an address that you created with a BCC wallet, the person who owns that BCC wallet would receive BTC. It won't appear in his BCC wallet, but if he has the same private keys on a BTC wallet, he would receive the coins there and be able to spend it.

Emphasis mine. Hopefully you have the private key!


The version of the mined block is 0x2fffe000 instead of 536870912.

Many miners employ a strategy known as overt Asicboost. This strategy requires modifying the version number like the nonce, so we often see blocks that have strange version numbers.

Only 194 transactions from the block template are in the mined block, e.g. f0fcac28b1dec7b8e67f73229052639c58f7f175bdb87ea068f499a4728bb35d. The other 1257 transactions are missing.

Each node has a different view of the set of unconfirmed transactions that depends on how long they have been running, where they are located, and any custom rules that they are using. It may be that your node has not been running for as long as the miner's node and so it has not seen all of the same transactions that the miner has seen. It may be that your node is using different rules than the miner is, possibly due to different versions of the same software, or possibly because some miners may be using custom software. Additionally, some miners offer a service where they will prioritize transactions after being paid out of band, so such transactions can end up in a block when they do not appear in a block template produced by your node.

What would have happened if a miner found a block hash for the received block template and submitted it? Would the mined block then have a different version and the missing transactions (including the transaction that was not even mined yet)?

There is no "current template" for the entire network. If there were, then there wouldn't need to be a blockchain as that would mean every node is actually in sync with every other node. As such, when a miner finds a block, they broadcast the block in full. When nodes receive a block, they verify it without creating their own block template. There are no requirements that the block contain the transactions a node expects it to contain. The only requirements are that the block contains valid transactions and that the block header is valid. Whether your node has seen those transactions before and whether it would include them itself are irrelevant.


"Failed to connect best block" error when I try to load my wallet Everytime I try to open my wallet this error comes up. I have  shut the computer down   a few times  and  removed the wallet and reloaded it a few times too and the error keeps happening.

If you can't see the picture, it is a error message which says "failed to connect to best block"   and  it makes the wallet not open.

Your database is out of sync with your blockchain.

Restart with -reindex-chainstate to make it rebuild the database. This may take several hours or more, depending on the speed of your machine and storage.


Testing Ledger Nano S wallet seed Can I test that I've correctly recorded the seed by "restoring" my wallet in a desktop wallet like Electrum by using the seed given to me by my Nano S?  It would mirror my hardware wallet, correct?

Is this safe / right way ?

If you do this correctly, it would mirror your wallet, yes. BUT!

Doing so is probably not a good idea, because you'll have to type your seed phrase into a desktop computer that may be compromised. The point of a hardware wallet is keeping your keys locked away in a device which never touches the internet, testing your backup seed phrase on an internet-facing device entirely undermines this.

Instead, it is best to test your seed phrase using the hardware wallet itself (or, a second one).

Initialize the hardware wallet, write down your seed phrase
Open the wallet software on your PC, copy the receiving address your wallet shows into a text file
Wipe/reset your wallet, and re-initialize it using the seed phrase
Once done, open the wallet software on your PC, and check to see if the receiving address is the same as the one you copied to your text file. If it is, then you successfully recreated the same wallet.

If you've already sent funds to your hardware wallet, then it may be worth removing the funds from the hardware wallet before doing this test (or, just do the recovery test on a second hardware wallet). You wouldn't want to wipe the wallet with funds on it, before you're comfortable with the recovery process.


Blockchain. An economist's dream? Suppose I was an economist wanting full knowledge of the EBS and flows of the economy; I want to know who buys from who, for how much, and I want to see who has accumulated what funds at what time. In short, I want to trace each element of this complex system we call the economy. But I don't need to know who is IBM, who is Ford, and who is Google. I "simply" need to separate IBM from Google and Ford in my analysis.

Suppose the whole economy functioned using the Blockchain, how useful is the Blockchain for my goal? And if not very useful, are there alternatives that are?

Blockchain by structure is a decentralised, distributed and public digital ledger that is used to record transactions across many computers, As blockchain is public everyone is able to see the blockchain content.

Your analysis could be my analysis and I will be able to separate IBM from Google..

You can't separate them if you don't know them. But with cryptography world
nothing impossible, i'm pretty sure someone with a "Big" cup of coffee will be able do it. But i'm talking about blockchain structure not programming skills.


New wallet per customer, or new address? So I'm in the process of starting a new service, but want to make sure I build the foundation correctly from the start. When customers deposit to their user account on my service, I need to understand whether I should be using one giant wallet with a new address for every customer and assign that address in the database against their user, or if I should generate a new wallet (with, presumably, new seeds) on signup for every customer, so each customer has their own unique wallet. What is the best course of action here? One thing to be aware of is how the backup process will go, and any potential race conditions (say someone generates themselves an address and sends coins, but the server gets wiped out and the backup doesn't have that last 10 seconds of activity, so the address that was generated can't be tied back to the appropriate user).

If you are looking to accept deposits from your customers then you should create one deterministic wallet using software like electrum and the install the extended public key aka xpub aka master public key (MPK) on the server. Then from that you can generate all the addresses you need.

The above creates a watch-only setup where you can generate addresses to receive bitcoin but not spend. So in case someone compromises your server they learn your entire transaction history but they can't steal from you. In order to spend the money you need to use the seeded wallet on your PC.

In order to associate addresses with users you would make a note of it in your app's database.

If you want to associate addresses with users in some deterministic fashion then you can assign each user an ID number and a counter which will serve as an address index. Then you can devise an appropriate derivation path that incorporates those two things. So for example Alice could be user ID 5430. Alice's deposit addresses are m/5430/i where i is the counter in the database. First Alice address would be m/5430/0, second would be m/5430/1 and so on. The user ID would not change once a user registers so even with slightly older backups as long as you have the user ID you can increment the counter until you get to the correct one.


Subscribe for market depth updates using Mt.Gox streaming API I want to subscribe to market depth updates using the streaming API https://en.bitcoin.it/wiki/MtGox/API/Streaming. I want to receive only depth updates for a particular symbol (EUR for example) or for all symbols.  So I connect to wss://websocket.mtgox.com and send the command

{
     "type": "depth",
     "op": "mtgox.subscribe"
}

I'm expecting to receive depth updates for all symbols. But it sends me updates only for BTCUSD. Though the same subscribe command with parameter "type" = "trades" sends trades for all symbols (not only BTCUSD). That's a little confusing.

The currency parameter is mentioned in API documentation: websocket.mtgox.com:80/mtgox?Currency=EUR, but after connecting to this websocket I receive ticker updates as well. But I don't need ticker updates.

The question is how can I receive only market depth updates for particular symbol? (or all of symbols)

Heres how I do it in node.js

var events = require('events');
var io = require('socket.io-client');

var MTGOX = function(){
    var self = this;
    var socket = io.connect('https://socketio.mtgox.com/mtgox');

    socket.on('message', function(data){

        var message = data;

        if( message.private == "depth"){
            self.emit('depth', data.depth);
        } else if( message.private == "ticker" ){
            self.emit('ticker', data.ticker);
        } else if( message.private == "trade" ){
            self.emit('trade', data.trade);
        }

    });
};

MTGOX.prototype.__proto__ = events.EventEmitter.prototype;

and then I just listen to the depth event. Also I found this project helpful when I was first figuring this out.


Is it possible to catch up missing blocks with zeroMQ if script was down for a while? I use zeroMQ to get all new blocks (rawblock or hashblock). If my script is down for few minutes or hours and I missed few blocks, is it possible to catch up all missed blocks with zeroMQ when I restart the script ?
During this time, bitcoin-core is always running.

No, it is not possible to catch up via ZMQ itself. A sequence number is present with each notification so you can detect when you've missed notifications. In those cases, then you can fetch the missing blocks and transactions over the RPC interface.


Derived address different from CLI to NodeJS Basically I'm trying to create a system in which each user has it's own address to deposit on the site, however I'm having issues with monitoring addresses as they appear to be different results within CLI & Node.

Here's the code used to import the private key based on derived user ID:

const { exec } = require('child_process');

const hdNode = bitcoinjs.bip32.fromBase58(config.BIP32_DERIVED_PRIVATE, bitcoinjs.networks.bitcoin);

exec('bitcoin-cli importprivkey "' + hdNode.derive(user.id).toWIF() + '" "' + email + '" false');

Okay, now for the user side of things, the derived key is displayed using the following:

var derivedPubKey = config.BIP32_DERIVED;
if (!derivedPubKey)
    throw new Error('Must set env var BIP32_DERIVED_KEY');

const hdNode = bitcoinjs.bip32.fromBase58(derivedPubKey, bitcoinjs.networks.bitcoin);

exports.deriveAddress = function(index) {
    return bitcoinjs.payments.p2pkh({
        pubkey: hdNode.derive(index).publicKey,
        network: bitcoinjs.networks.bitcoin
    }).address;
};

However both results appear to be completely different? if I type bitcoin-cli listreceivedbyaddress 1 true into my SSH I get the following result:

But then for this same account, on the user interface I get the following:

bitcoin-cli is generating a P2WPKH address (bc1...), but then on the user side you are generating a P2PKH address (1....).

You may also need to check to ensure the same address derivation path is being used (Bitcoin-core uses hardened derivation).

For more info on address encodings see:

What is P2PK, P2PKH, P2SH, P2WPKH - ELI5

What is the size of different Bitcoin transaction types?


How to get a balance from the network directly? I was under the impression that I'd be able to get a balance from the network directly, not only by going through some http interface which wraps the server RPCs.
I am curious, is it possible to get a balance by hitting a node on the network directly? I've tried using curl to hit every node on the network already.
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": ["*", 6] }' -H 'content-type: text/plain;' http://${server}/

The documentation says to include the --user flag, so I believe this is why the calls fail.
If not, how is my Trezor able to operate independently? Does my Trezor depend on Trezor.com running a node?
Also, I am curious, some APIs must be open, for example a new node which wishes to sync must be able to fetch blocks from it's peers, but I see that getblock RPC also requires authorization, i.e. "curl --user"...
https://bitcoincore.org/en/doc/0.20.0/rpc/blockchain/getblock/
What APIs do nodes in the network expose directly? Any?
Thanks!

Bitcoin nodes have no idea of what a "balance" is, that's a concept that wallets have. The Bitcoin peer to peer network allows for the communication of transactions or blocks (neither of which contain "balance" information), and nothing else. There is also no portion of the private RPC API which will tell you the "balance" of an arbitrary address either (it can tell you detail about a locally running wallet with getbalance however), and these interfaces are never made public because they allow almost complete control of the nodes wallet and operation.

Does my Trezor depend on Trezor.com running a node?

With their software as supplied, absolutely. If you use it with another piece of software locally it is usually the case that you're trusting a remote party, but there's the possibility of setting it up in such a way that it does not. For example, Electrum, but only when connected to Personal Electrum Server, which runs locally as a middle man between a Bitcoin node you operate and Electrum.


How can I generate bitcoin cash addresses programmatically? If I'm a mobile developer who wants to integrate bitcoin cash in an app, how can I generate Bitcoin Cash addresses programmatically, without relying on a 3rd party service, like Coinbase?

You can use the following library to generate bitcoin address using Swfit on IOS

https://github.com/onmyway133/AddressGenerator

Please note that the legacy bitcoin cash and bitcoin address is the same the only difference is the network.

if you're looking for cashAddr (qq address) format, take a look on these open source libraries:

https://github.com/bitcoincashjs/cashaddrjs (javascript)
https://cashaddr.bitcoincash.org/
https://github.com/schancel/cashaddr-converter

Original cashAddr algorithm (C++)

https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/cashaddr.cpp

it's pretty easy to read and understand, you can translate it to any language.


Why can we have small fractions of a Bitcoin? I didn't study the inner workings of Bitcoin (yet), but already since when I just started using it, I wondered why a Bitcoin can be split up in parts.
Because there is a limit on the amount of Bitcoin that can be mined ever, fractioning Bitcoins is a huge advantage, especially if it's popularity increases.
Is there a limit on splitting Bitcoins into pieces?

EDIT:
I just found in this answer that BTC has a maximum of 8 decimals. Is it a good assumption then that every "BTC" consists of 10^8 smaller parts? So every block does not consist of 50 1-BTC parts, but 50*10^8 smaller parts?

Bitcoin amounts in the protocol and software are expressed as an integer number of "satoshis". 1 BTC is defined as 10^8 satoshis. So a block reward that is internally represented as 5*10^9 satoshis is displayed in the GUI as 50 BTC.

Splitting bitcoins to even smaller fractions will require a change in the protocol and software, and may be done when their value becomes much larger.


Bitcoin Core - Bought bitcoin to a 'sending address', what can I now do, nothing is showing up in my transactions As the question says, on the wallet, bitcoin core, under file you can find 'sending addresses' and 'receiving addresses'. In a moment of absolute stupidity I copied one of the sending addresses when buying some bitcoin. The transaction is marked as having occured on bittylicious but no transactions appear on my bitcoin wallet - what can I do?

If you provided one from your sending instead of receiving consider those coins donated. Your wallet only shows transactions on addresses you own.

What you can do is try to figure out what address you provided them. I've never used the service you mentioned but they probably have the transaction ID available. Once you find out the address try to remember what you used that address for in the past. Your coins might be on an exchange or website you used before.


Error help! "A fatal error occurred. Bitcoin can no longer continue safely and will quit." I synchronized fully, replaced the wallet.dat file, rescanned and this happened.

My debug log:
https://drive.google.com/file/d/0B7me4XCWsORySzdMMEpYWU5Lakk/view?usp=sharing

Screenshot of Error:

It appears that your wallet.dat file is corrupted. From your log files with the original copy of the wallet, it looks like you made that copy of the wallet before Bitcoin Core closed the wallet database (which actually includes more than the wallet.dat file but those other files are temporary and only exist when the database is open) which has resulted in corruption.

Since you have already used -salvagewallet on a different wallet file, just use that wallet.dat file. Note -salvagewallet has some issues and is not guaranteed to fix corruption. Because your wallet is old enough, it does not use HD keys, so the following workaround should work: start Bitcoin Core with the -usehd=0 option or add usehd=0 to your bitcoin.conf file.

This is a workaround and should allow you to open your wallet and retrieve your private keys. Your wallet.dat file is still corrupted and you should stop using it immediately. You should move your coins out of that wallet file ASAP by following the instructions here.


Best practices for storing the bitcoin blockchain? I have a few questions. One, is an SSD a good option to store the bitcoin blockchain. To unpack that question more, historically, has the blockchain size kept pace with Moore's law in relation to SSD technology?

Second, is a SAN drive array more appropriate to store bitcoin and other blockchains? I have done this before, it worked for my purpose as bitcoin is rather dynamic and slow compared to a typical database. The storage size is a clear upside. However, I wonder what is the impact with many big queries and also sync times?

I have done extensive tests without SDD, and later on with SSD. For sure downloading the bitcoin blockchain does not (!) require an SSD. However, everyone knows, it is faster using an SSD. There is heavy disk I/O, storing the blockchain, and there is also heavy CPU usage (re-) calculating the values, before they are stored on the local drive. One can give parameters to the bitcoin core client to increase memory usage (to speed up process), and you can for sure try to play with OS cache. So you need a fair amount of power to get along, and balance the parameters.

The bitcoin blocksize growth is pre-determined, so Moore's law is less relevant, and the blockchain growth is much, much less than Moore's law. Back to SAN: I had an older 1GB/sec attached SAN drive, with redundancy behind, and downloaded the blockchain on a 2 CPU machine. There was no problem, and it took only ~30% of my comparable desktop machine with an INTEL i7 processor (Unix OS).

Reliability of data is given through the SAN architecture, and the query speed is sufficient: you query the blockchain "sequentially", and for sure this is slow. Depends on your use case... But this is independant from the disk subsystem. However, the big "online explorers" (blockchain.info...) re-index the blockchain into the specific addresses, tx IDs and more, so that requests attain a satisfying speed.


What was the market cap of Bitcoin before and after the Bitcoin Cash fork? I'm trying to understand the mechanics of the hard fork that created the Bitcoin Cash blockchain on August 1, 2017. After the fork, each holder of BTC got the same amount of BCH as they had BTC.

My question is around what happened to the market cap of BTC as BCH emerged. Specifically, what was the aggregate market value of all BTC immediately prior to the fork and then immediately after.

I've tried looking for this in different forums, but can't find a reliable source.

On 31 July 2017 Bitcoin had 51.48% of total market cap.

On 1 August 2017 Bitcoin had 43.04% of total market cap where as Bitcoin Cash had 10.77% of total market cap.

For more information about market cap https://coinmarketcap.com/charts/


Where do the majority of Bitcoin transactions take place? I'm new to Bitcoin and am trying to wrap my head around where and when bitcoins are used.  I understand that Bitcoin is accepted by a lot of legitimate websites (now reddit, wordpress, etc) for digital goods or services and there are also online market places that sell physical goods.  There also seems to be a lot of illicit activity transacted in Bitcoins since it is (fairly) anonymous.

My questions are basically:

What types of things is bitcoin buying and for what percentage of the total transaction volume are these things responsible?
How much of the transaction volume is responsible for physical or digital goods as opposed to just bitcoin trading?
Are these markets sustainable or are they likely to disappear (i.e. the illicit activity)?

Because bitcoin is a pseudonymous digital currency, there are no hard statistics available.

Because one popular service, SatoshiDICE, uses static Bitcoin addresses as the wagering mechanism for the players of its online "Dice" game, the amount of activity related to them can be measured.  It currently represents the majority of bitcoin transactions (but not value) that crosses the network.

Currently the Bitcoin network is hitting about 50,000 transactions per-day.  Some of these transactions will be performed for the purpose of mixing coins to protect the privacy of the sender.

By far the biggest interest in Bitcoin to-date (going from an educated guess) has been for speculative and investment purposes.  As such a large amount of the activity is transfer of funds to and from (and between) exchanges.

The ratio of this type of activity versus commerce involving digital and physical goods will heavily favor the speculative/investment but by to what degree is unknown as that data is not shared by the private parties who trade these goods and services.  If it were a ratio of 25:1, that would not be surprising to me.

While the ratios may change over time as bitcoin gains traction for more mainstream use, any use established at this early time will likely continue -- it will just represent a shrinking slice of a rapidly growing pie.


blockchain unconfirmed and unspent output sent btc to a miner for a mining contract, but while i was sending the btc, they timed out the offer.   Now my btc are sitting in limbo, pending transaction, unconfirmed and unspent.
4167a51abe68851d04733204ed069755224555075b72a89a70feccb2ad032efc

Any solution other than hope for blockchain to return it to my account?

This thread has general answers about unconfirmed transactions.

In your case, if the tx is confirmed, then you will have to communicate wit the counterparty (the miner) to ensure they fulfill their end of the transaction. If it does not confirm, your coins will become spendable again (see that thread for more info).


"Bit Coin Investigators" or Consultants for hire - to help locate a Bit Coin account after a person has died? Do you know where I can obtain a List of "Bit Coin Investigators"
 or  -  Consultants for hire -
to help locate a Bit Coin account after a person has died?

Do you know where I can obtain a List of "Bit Coin Investigators"

There isn't any established list.

You need to be very careful about trusting strangers on the Internet, there are many crooks looking for people like you. They will ask you for a fee to retrieve the Bitcoins, then ask for additional fees using various technical-sounding reasons until they have bled you dry.

Remember that you are putting an extreme amount of temptation in the hands of any potential helper, it would be so easy for them to take everything away for investigation and later tell you the "bitcoin wallet" was empty - or contained some small amount they thought would satisfy you. Even respectable people working for respectable lawfirms sometimes embezzle their customers money. The temptation is so much greater when the chances of anyone discovering their deceit can be near to zero.

  I have my grandson's computer & iPhone & drive, but don't know how to find his Bitcoin account info.

Unless you know his passwords, it is likely be impossible to ever gain access to any of his Bitcoins.

Unless he was an extraordinarily careless sort of person, he won't have the passwords for his bitcoins stored on his computer or on his iPhone - at least not in a form where you can easily find them.

You could try to find if he had a "paper wallet" - a piece of paper with a string of 36 digits and letters written down or a set of twelve words (sometimes there are eighteen or twenty-four words) which form what is called a "recovery phrase". If you find those, put them aside somewhere very very safe, keep them secret from any helpers, then spend some time learning how to create a bitcoin wallet on your own computer (don't use an online wallet), when you have some experience buying and spending bitcoin, only then, import the key or use the recovery phrase to gain access to your grandson's bitcoins.


Who has named 10e-8 BTC "Satoshi"? When and where did the term come up for the first time? Did Satoshi Nakamoto comment on the naming?

I'll list the mentions I've found in reverse chronological order.

It first showed up on StackExchange on August 30, 2011.

  However, I often hear the term Satoshi as if it was a monetary unit.

rebuilder discussed the divisibility of Bitcion on March 23, 2011.

  I'll use the term "Satoshi", as previously coined by others, to mean the current smallest available Bitcoin unit.

On February 18, 2011, kiba said,

  I can't wait to use satoshi to denote a very small fraction of bitcoin.

marcus_of_augustus replied,

  1 satoshi = 1 microbitcent (smallest denomination)

  100 million satoshis = 1 bitcoin

  Are we agreed?

I cannot find anything earlier on bitcointalk.

  Did Satoshi Nakamoto comment on the naming?

I cannot find a searchable copy of his writings. If I can, I'll update this answer. However, his postings were already tapering off at February 2011, so probably not.


How do I Derive Bech32 Address from P2WPKH Output Script? I am building a small script to decode the raw coinbase transaction data into a human-readable viewer without external scripts to better my understanding around the subject.

I've noticed that there are many different types of output script types among transactions. (P2SH, P2PK (as seen in genesis block), P2PKH, etc)

One thing I have not been able to grasp is how to obtain the Base58 address in the new SegWit P2WPK and P2WSH types.

For example, Block #542748 has this coinbase transaction which my script determines to have a pay to witness public key (P2WPK) output with 97cfc76442fe717f2a3f0cc9c175f7561b661997 as the public key hash.

The full output script: 0[] PUSHDATA(20)[97cfc76442fe717f2a3f0cc9c175f7561b661997]

Traditionally, in P2PK, P2PKH and P2SH I've used the image on this thread which works quite well.

When I apply the same method as the pubkeyhash (P2PKH) with the following operations I get a totally different address:

Append version byte:
0097CFC76442FE717F2A3F0CC9C175F7561B661997

SHA-256 Round 1:
f756795a3b878d16bfa9e426a47d857830bb08a02e691f0487cbeac51b510f40

SHA-256 Digest of Round 1:
ea7fe8c3b7680b79ff507c7d1b40bfc29ca8269bb1033cc84010506743cce404

Append checksum 4 bytes: 0097CFC76442FE717F2A3F0CC9C175F7561B661997ea7fe8c3

Base58 Encode: 1EqhwhM5t5NxedLoSuJ6BtBvUMLhanBLxa

This is quite different than bc1qjl8uwezzlech723lpnyuza0h2cdkvxvh54v3dn which is listed on blockchain.info's website here

What's the best way to obtain the same address they have listed (starting with bc1)?

Okay so I think I've figured it out for anyone else wondering what exactly you have to do to derive an address from this type.

In the case of the already mentioned transaction, (coinbase of block 542748) we first start by looking at the full decoded output script.

0 PUSHDATA(20) 97cfc76442fe717f2a3f0cc9c175f7561b661997

The very first OP_0 in the decoded script is the witness version
We then take the data pushed (in our case 97cfc76442fe717f2a3f0cc9c175f7561b661997) and convert it into binary
Then we divide the binary into 5 bit sections. In our case: 10010 11111 00111 11100 01110 11001 00010 00010 11111 11001 11000 10111 11110 01010 10001 11111 00001 10011 00100 11100 00010 11101 01111 10111 01010 11000 01101 10110 01100 00110 01100 10111
Then we prefix the witness version in 5 bits 00000
Our binary then becomes 00000 10010 11111 00111 11100 01110 11001 00010 00010 11111 11001 11000 10111 11110 01010 10001 11111 00001 10011 00100 11100 00010 11101 01111 10111 01010 11000 01101 10110 01100 00110 01100 10111
The first part of the address is considered the human readable portion.
This is always bc on the mainnet and tb on the testnet
1 is always the seperator between the human readable portion and the rest or data
Now our address starts with bc1 (mainnet is bc + seperator 1)
Now we map each 5 bits into the table here - or this alternative chart I've created
bc1 qjl8uwezzlech723lpnyuza0h2cdkvxvh
The remaining 6 characters is a checksum
Using the provided python code here we can compute the checksum using the bech32_create_checksum function
The first argument is the human readable portion as a STRING without the seperator (1)
The second argument is an array of integers converted from our binary data portion

Our example:

bech32_create_checksum("bc", [0, 18, 31, 7, 28, 14, 25, 2, 2, 31, 25, 24, 23, 30, 10, 17, 31, 1, 19, 4, 28, 2, 29, 15, 23, 10, 24, 13, 22, 12, 6, 12, 23] )

This gives us:

[20, 21, 12, 17, 13, 19]

Which can be mapped with our table to 54v3dn

Finally, we concatenate the human readable, seperator, decoded data, and the checksum for our final address: bc1qjl8uwezzlech723lpnyuza0h2cdkvxvh54v3dn


Migrating from Electrum => Bitcoin core Seems that many people become scared as soon as they seen 1 week or over and discover they've to download the full blockchain(ca. 60 GB now required), so it's full of question about migrating from bitcoin core to electrum? But what about vice versa? Bitcoin core doesn't support sweeping, but it should support, by command line, importing private addresses.
First questions, I read there is dumpwallet, is there a importwallet option that allow to import more than 1 private key at time? This could be a simply option, import all keys at time. Import each keys with importprivkey can be a long operation.
Then, 2nd option, is just send electrum btc to a bitcoin core address right? What about get the electrum wallet, is bitcoin core able of read it in some ways (not with external software)? Is there a way to safely convert?

Yes, importwallet exists.

Coverting a wallet from Electrum to Bitcoin Core is very hard, as both pieces of software have a very different idea of what a wallet is. Electrum relies on servers that provide indexed blockchain information to discover transactions, so its wallet does not store much information. Bitcoin Core needs all your transactions and keys actually available in the wallet so that it can operate independently.


Why longpoll if sockets are available? I've noticed that the bitcoin client uses sockets.

I've also seen that long polling is not only available but is also recommended.

Why?  Isn't long polling far less efficient than sockets?

Don't confuse the way bitcoin clients talk to each other (peer to peer, speaking the Bitcoin protocol) with the way the bitcoin client talks to RPC clients (server to client, with bitcoind acting as an HTTP server speaking JSON-RPC).

When the bitcoin client speaks RPC, it uses HTTP. Long polling is much more efficient than HTTP without long polling, which is why long polling was created and why it's recommended if you're using RPC.

However, using RPC for miners to talk to the systems that issue them work is rapidly becoming obsolete. Stratum replaces that, and it uses a native method that's more efficient than long polling.


get the real last block I have this code:

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
rpc_user='-------' #User name is hidden
rpc_password='-------' #Password hidden
logging.basicConfig()
logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)
rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))
blockcount=rpc_connection.getblockcount()
print(blockcount)

The result:

DEBUG:BitcoinRPC:-1-> getblockcount []
DEBUG:BitcoinRPC:<-1- 94768
94768

Of course this is last block in my device, but I want the real last block.

Is there a "external server or a Web site" i can call instead of Local server '127.0.0.1'? (for sending the bitcoin RBC method)

Instead of getblockcount, you can call getblockchaininfo and read the headers field.

However, while this may give you a lot more blocks than the local block count, you will still only receive a count up to the point where your node has synced headers (which can be limited by time, network, how well synced your peers are)

There is no way to always get the latest block height reliably from an unsynced node.


What is the duration of a ban? I read somewhere that a node is banned for 24 hours.

However I found the Misbehaving() function which makes state->fShouldBan = true;. But I could not find any other function that makes state->fShouldBan = false;. It seems that banning is forever.

If banning is forever, I guess the node also removes the misbehaving peer from its neighbor list, right? But I could not find it.

When state->fShouldBan is set, the network thread will disconnect the node, and cleanup memory. As a result, the state object disappears entirely. Because of that, there is no need to ever unset fShouldBan.

What does happen is that when the actual ban happens (not just the setting of the fShouldBan field), it is added to the ban table (which is IP based). Entries in this table have an expiration time. The default expiration time for newly banned nodes is controlled by the -bantime option and defaults to 24 hours in the future.


What are checkpoints? I often read that checkpoints protect the network from a 51% attack because an attacker cannot reverse transactions made before the last checkpoint.

How exactly does this checkpoint mechanism work? And who creates the checkpoints?

The checkpoints are hard coded into the standard client. The concept is, that the standard client will accept all transactions up to the checkpoint as valid and irreversible. If anyone tries to fork the blockchain starting from a block before the checkpoint, the client will not accept the fork. This makes those blocks "set in stone".


What is a txn? How can it be invalid? I read this in a IRC exchange:

  verifies your txns against a random node that you don't control. if for some reason that node went rogue, you might have accepted an invalid txn

What is a txn?

"txn" is short for "transaction".  The abbreviation "tx" is also often used.

For an explanation of what makes a transaction (in)valid, see the links at How to know if a transaction is valid?


Is it legal to use rented dedicated servers to mine? I've got several dedicated servers which I'm renting for about 250 Euros from a big hoster (OVH). These server are used for things like ssh/scp, SVN and Git servers (for private repositories), HTTP proxy, etc.

Nothing shaddy here: just fully legal servers that see little use.

I realize these servers are really not powerful at all and would make terrible miners (at least for all the cryptocurrencies where GPU and ASIC mining is disproportionally powerful compared to CPU mining): that is not the point of my question.

My question is: can you legally use a dedicated server which you fully pay for to mine cryptocurrencies all year long? Basically I realized that the CPUs would be running at full speed and would consume more electricity than the way I use them now.

It's definitely not against the law. It might be breaking the terms of service (ToS) but there's really no reason why any dedicated server hosting provider wouldn't allow you to max out the CPU. I wouldn't do business with them if they limited that. However, you need to read your hosting provider's ToS. They might forbid certain applications like IRC servers, BitTorrent, Tor, etc. If they don't list Bitcoin then you are good to go.


What happens once mining speed gets close to zero? According to Wikipedia

  The number of Bitcoins created per block is never more than 50 BTC, and the awards are programmed to decrease over time towards zero, such that no more than 21 million will ever exist.

from which I naively conclude that as time passes less and less bitcoins will be mined and the total amount of bitcoins is limited, so after say ten (or whatever actual number - doesn't matter) years mining a bitcoin will be as unlikely as winning big in a lottery and maybe even news will report that one more bitcoin has been mined.

Are those right conclusions? What exactly happens once mining speed gets close to zero?

I think you are confusing two things here:

Block generation rate
New bitcoins introduced per block

Blocks will always be found at a rate of approximately one per 10 minute. The difficulty of finding a block adjusts itself according to how many people are trying. Simply said, if N people are mining (all with equal hashing power), they will each (on average) find one block per N*10 minutes.

On the other hand, the newly introduced currency in each block is currently 50 BTC/blocks, but somewhere end 2012 this will decrease to 25 BTC. 4 years later, it will become 12.5, and so on. Around 130 years from now, the last block with non-zero new coins will be created. After that, mining will still continue, but blocks will only have transaction fees as rewards, and no new currency anymore.


Is there a way to set up proof-of-work systems so they would be even more useful? One of the arguments made against Bitcoin's design choices is that it wastes resources authenticating transactions. In particular, finding small hashes is completely useless for the world.

Are there approaches (or other crypto-currencies) that use proof-of-work by working on some useful difficult problem? There are plenty of projects like SETI@home or Folding@home that distribute difficult but potentially useful calculations among different users, is there a way to use such useful calculations for building a proof-of-work system in a crypto-currency, or is there a fundamental reason (economic or computational) that a proof-of-work must involve useless work?

I think the premise of the question is not correct. The work is not useless, it secures the transactions. The public hash chain ensures that Bitcoins can only be spent once. The mechanism piles computations on top of legitimate transactions so that the recipient knows that an attacker would need at least as much computing ability to "undo" the transaction.

There is currently no known way to make the work more useful. The problem is that the primary purpose of securing transactions imposes a number of requirements on the work done:

The work must be much, much easier to verify than to do. So it pretty much has to consist of searching for something rare, doing billions of searches to test if an input has a particular characteristic. That way the verification simply requires confirming that the input you found has that characteristic.
The work must in fact secure the transactions and not be severable from them. If I see that you sent me 10 Bitcoins and then billions of computations are piled on top of that, it must not be possible to remove that transaction and then pile those same computations on top of a conflicting transaction. So you can't use the result of an arbitrary chunk of work to prove work on the Bitcoin chain.

It's hard to imagine any additional useful work that could be accomplished while still meeting these requirements.


no schema for stratum I am trying to bring up stratum mining on a pool and get this error -> exceptions.Exception: There is no shares table. Have you imported the schema?   Obviously my database is empty but no package I have download from git has a single .sql file to populate the db.  How do you populate the schema?

https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide
https://github.com/ahmedbodi/stratum-mining/issues/97

gentoo001 stratum-mining # locate .sql
/usr/portage/dev-db/mysql-udf-base64/files/mysql-udf-base64.sql
/usr/portage/mail-filter/gld/files/tables.sql
/usr/share/doc/mysql-5.1.70/scripts/mysql_fix_privilege_tables.sql.bz2
/usr/share/doc/mysql-5.1.70/scripts/mysql_system_tables.sql.bz2
/usr/share/doc/mysql-5.1.70/scripts/mysql_system_tables_data.sql.bz2
/usr/share/doc/mysql-5.1.70/scripts/mysql_system_tables_fix.sql.bz2
/usr/share/doc/mysql-5.1.70/scripts/mysql_test_data_timezone.sql.bz2
/usr/share/mysql/fill_help_tables.sql
/usr/share/mysql/mysql_fix_privilege_tables.sql
/usr/share/mysql/mysql_system_tables.sql
/usr/share/mysql/mysql_system_tables_data.sql
/usr/share/mysql/mysql_test_data_timezone.sql

This table isnt part of the MPOS schema you have to create it yourself, my schema for this table is:

mysql> show columns from shares;
+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| shareID         | int(11)      | NO   | PRI | NULL    | auto_increment |
| rem_host        | varchar(100) | YES  |     | NULL    |                |
| username        | varchar(100) | YES  |     | NULL    |                |
| our_result      | varchar(255) | YES  |     | NULL    |                |
| upstream_result | varchar(255) | YES  |     | NULL    |                |
| reason          | varchar(255) | YES  |     | NULL    |                |
| solution        | varchar(255) | YES  |     | NULL    |                |
+-----------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

I keep this in a seperate db to MPOS but there is no reason you cant add it manually to the MPOS table.  I will also add that while this works I'm not certain if varchar is the correct datatype to use here.


How can I create HTLCs below dust_limit_satoshi in Lightning Network? BOLT#2 documentation for open_channel message has two points (dust_limit_satoshi and htlc_min_msat) in the data message that I found confusing. Below is the statement related to dust_limit_satoshi:

  dust_limit_satoshis is the threshold below which outputs should not be generated for this node's commitment or HTLC transactions (i.e. HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain)

and for htlc_minimum_msat

  htlc_minimum_msat indicates the smallest value HTLC this node will accept.

My question is how will I be able to accept a htlc with value that is in sub-satoshi, if my dust_limit_satoshi is in Satoshis? As per my understanding and the first statement in quotes, my node will not accept HTLC transactions that are below the dust_limit. If that is the case why not enforce that htlc_minimum_msat > dust_limit_satoshi?

The dust limit is an externality to lightning wich the protocol has to respect. In fact if a commitment transaction would encode an htlc below the dustlimit you could not force close the channel as the Bitcoin network would not accept that particular transaction.

When it comes to htlcs below the dustlevel we work with a little trust in the payment channel. This means that offering an htlc means that we remove some bslance from our side of the channel. Instead of making it an htlc output we just add it to the fees of the commitment transaction. Technically our channel partner could harm us by force closing now and our htlc amount would be lost forever if we don't find the preimage. Only upon delivery of the preimage a new commitment tx is negotiated in which the fee is reduced by the htlc amount and added to your channel partners balance.

That being said. For fee calculations of small payments we even allow subsatoshi amounts which again are not enforceable and will be added to the fees by rounding down the actual balance in the commitment tx. Any routing nodes could implement (actually just configure) a rule like the one you suggested. This would enforce the effect that the channel can be operated fully trustless.

I can't tell you why this is not encoded to the protocol. I think because people wanted to allow micro transactions


How to generate btc addresses from XPUB? I have an xpub key and I'd like to generate the sequence of btc addresses in PHP based on the index.
Is there a way to do that?

You can use https://github.com/denpamusic/php-bitcoinrpc to call methods defined in Bitcoin Core API Documentation.
Getting addresses from xpub: https://bitcoincore.org/en/doc/0.20.0/rpc/util/deriveaddresses/


Nonce size - Will it always be big enough? If I understand correctly, the block only has 4 bytes (32 bits) for the nonce.
Is it possible for the difficulty to become high enough that there are no nonce solutions?
If so, then what options does a miner have?

The difficulty is already to the point where it requires over a quadrillion hashes to solve a block. 2^32 is only 4 billion. Fewer than one in a billion times will there be any nonce that makes the block valid.

A miner simply has to try every possible nonce on a different block. He can vary the coinbase, the transaction set, and/or the block timestamp. Any change to any of these things results in a new chance for there to exist a valid nonce.

Often the best choice is to bump the timestamp, a practice called NTime rolling.

The block timestamp doesn't have to be exact anyway, so you can back the timestamp back, say, ten seconds before you start mining and then bump it up 20 times before giving up and getting a new block. At worst, your block timestamp will be off by a dozen seconds or so -- nobody cares about that.

After that, you probably want to get a new block because there might be some new transactions to include -- this not only improves the efficiency of the network as a whole but reduces the chances you'll miss out on a transaction fee.


Genenerate address offline, but blockchain knows about my address I generate new address in client. I hear that blockchain doesn't know about it. Blockchain will know about it when I use this address for transaction.

My example:
I generate this address(offline): 1J1JqUPqKq4XvrDRioMSMYKrwL3wKdJ1Fe
I haven't used yet. How does website blockchain.info know about my address??? https://blockchain.info/address/1J1JqUPqKq4XvrDRioMSMYKrwL3wKdJ1Fe

It only knows anything about the address because you asked about it.

Since the address has never appeared in the blockchain, all it knows is what can be seen from the address: its hash160 value. This is the hexadecimal version of what is encoded in your address, which is a hash of your public key via the algorithm explained here.


How Do HD Wallets Keep Track of all accounts? If a HD Wallet generates 1,000 accounts for example.

How would they keep track of all of the account's balances, if someone for example, paid into the 455th account, they would want to update the wallet balance.

I imagine that storing all of the accounts would not be efficient, and querying the blockchain or an API for all 1,000 would not be efficient either.

Using an isolated use case:

If an API HD wallet generates 1,000 addresses, it cannot query all 1,000 each time the user starts up the phone, and it cannot do it periodically because with everyone hitting the same endpoint, it would be a bottleneck.

I do remember blockchain.info allowing you to query with your extended public key, I imagine that they iterate through the accounts the same way using the gap limit.

In general, HD Wallets use the following logic for how many addresses to query, and when to stop:

Start with account 0, generate gap limit number of addresses (usually 20)
Check for any transactions in those addresses
If there are no transactions, stop searching for new addresses and accounts
If there are transactions, generator gap limit more from the index of the last address with transactions on it. Additionally, also do this process for account 1 (you only check for n+1 accounts if Account n has transactions

The general idea is that no accounts will exist if the previous account is unused, and that no addresses in an account will be used after a single, consecutive block of gap limit number of unused addresses.

Companies like BitGo who offer HD wallet services to exchanges etc. where you can easily have thousands of unused addresses in a row, and then addresses with transactions, generally ignore the gap limit. They instead maintain a list of all generated addresses and index them as individual addresses, not as an HD wallet.

On the API side of things, wallets generally try to keep a running index. They will maintain a cache of known transactions, and keep appending to it. This way, when you start it up, it only scans for transactions in the new blocks since the last time it scanned. This allows even light clients such as Electrum or Ledger/Trezor wallets to serve thousands of users with just a handful of nodes, since each wallet will not requery for previous transactions it alread knows about.

Naturally, if you import a frequently used HD wallet to a new wallet or delete the cache, the initial sync can take very long. However, subsequent syncs of the wallet will be much faster.

In addition to this, HD wallets will often rely on a full node (such as Bitcoin Core) or a system such as ElectrumX or Insight. All of these are capable of maintaining a full index. Bitcoin Core maintains only a running index across known addresses (which is why you need to rescan when you import an address). ElectrumX and Insight maintain an augmented index which keeps track of all transactions, and can quickly return data for any given address.

HD Wallets do continue to check for transactions across all used addresses. They simply don't rescan the entire chain every time. But for every new block, every tx in that block will be checked for every address in the HD wallet. This check can be done quickly via bloom filters or preindexed data such as from Electrum or Insight, without reaching a bottleneck.


Generate multiple public bitcoin receiving addresses (HD wallet) from seed phrase in nodejs I want to generate a new receiving address for my bitcoin wallet for each new user. Bitcoin transferred to all these address should be received in my bitcoin wallet. I don't want to expose my private key or seed on the server.I found that this is how HD wallets work so I tried this.

const bip39 = require('bip39')
const bitcoin = require('bitcoinjs-lib')   //ver 3.0.2

let phrase = 'width humor wheat sad obscure outer ancient grab edit labor record express devote humble recipe occur refuse tooth original fluid learn scheme fuel assault';
let seedBuffer = bip39.mnemonicToSeedSync(phrase)
// <Buffer 85 19 18 81 cf 0e cc f7 9c 5d 61 ......

let masterNode = bitcoin.HDNode.fromSeedBuffer(seedBuffer)
// Deriving the first account based on BIP44
let account0 = masterNode.derivePath("m/44'/0'/0'")

let xpubString = account0.neutered().toBase58()
console.log(xpubString)
let address0FromXpub = bitcoin.HDNode.fromBase58(xpubString)

let address0 = address0FromXpub.derivePath("0/0").keyPair.getAddress()
let address1 = address0FromXpub.derivePath("0/1").keyPair.getAddress()
let address2 = address0FromXpub.derivePath("0/2").keyPair.getAddress()
let address3 = address0FromXpub.derivePath("0/3").keyPair.getAddress()
// address0.toBase58()
console.log("address0",address0)
console.log("address1",address1)
console.log("address2",address2)
console.log("address3",address3)

but I tried sending bitcoin to the generated address and didn't received any? If anyone could help.

If you want to do Bitcoin stuff in nodejs, I recommend using bcoin:

repo: https://github.com/bcoin-org/bcoin

docs, guides: https://bcoin.io

It has a fully-validating full node implementation, SPV implementation, and BIP44 wallet that is used by Purse.io and several other Bitcoin-accepting merchants for this exact use case: Each customer gets a dedicated account and the wallet can track balances per-user, generating new addresses each time the current receive is used (a la BIP44)

You can set up your server with a watch-only wallet to report incoming deposits, and keep the private keys either offline or on more secure, local machine.

Example:

On secure or offline machine:

$ bcoin --daemon
$ bwallet-cli mkwallet --witness=true --id=HOT
$ bwallet-cli --if=HOT account get default
{
  "name": "default",
  "initialized": true,
  "witness": false,
  "watchOnly": false,
  ..
  "accountKey": "tpubDD3BFBuLYg2cspeDSWZgo9qv4qYi7KQF5oov8theqbFRUFqXPmsowPqAY1PQqnEdUe5JrFqf8ZGWLwEQEKB5WjJjxgMwcXmFuu1XDrG4RSr",
  ..
}

On "hot" production server:

$ bcoin --daemon
$ bwallet-cli mkwallet --id=WATCH --watch-only=true --account-key=tpubDD3BFBuLYg2cspeDSWZgo9qv4qYi7KQF5oov8theqbFRUFqXPmsowPqAY1PQqnEdUe5JrFqf8ZGWLwEQEKB5WjJjxgMwcXmFuu1XDrG4RSr
$ bwallet-cli --id=WATCH address default
{
  "name": "default",
  "account": 0,
  "branch": 0,
  "index": 1,
  "witness": false,
  "nested": false,
  "publicKey": "026f1afcab2942fd932760557943b287957bb8aa6ebe0f8dc64fa25862e23d52a2",
  "script": null,
  "program": null,
  "type": "pubkeyhash",
  "address": "mjdcszSLXHd6awrnM4bgJiFEbTFZdyw7de"
}

...etc

From here you can use API calls to create transaction templates and sign them on the offline machine.

If you are queasy about running an alternative implantation of Bitcoin, you can still run bitcoind on the hot server and run bcoin behind it (even in SPV mode) with bitcoind as it's --only= peer, like a Bitcoin Core Firewall

(edit)

Generate static addresses

'use strict';

const bcoin = require('bcoin');
const m = bcoin.Mnemonic.fromPhrase(
  'abandon abandon abandon abandon abandon abandon'
  + ' abandon abandon abandon abandon abandon about');
const master = bcoin.HDPrivateKey.fromMnemonic(m);
const key0 = master.derivePath("m'/44'/0'/0'/0/0");
const ring0 = new bcoin.KeyRing({privateKey: key0});
console.log(ring0)

Will output:

{
  witness: false,
  nested: false,
  publicKey: '03aaeb52dd7494c361049de67cc680e83ebcbbbdbeb13637d92cd845f70308af5e',
  script: null,
  program: null,
  type: 'pubkeyhash',
  address: '1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA'
}

You can verify this is address 0 from that mnemonic phrase using https://iancoleman.io/bip39/ and of course because this phrase is so abysmally insecure and used by developers testing on mainnet (sigh) there are several transactions to this address: https://blockstream.info/address/1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA


Has anyone attempted to rewrite the bitcoin software and protocol? As anyone who has looked at the bitcoin protocol in depth can tell, it is really a huge mess of different encodings, hashing styles, and endian conversions. Although it would be a fairly cosmetic change, are there any projects out there to attempt to rewrite bitcoin and it's protocols to be more consistent and easier to maintain for the developers? (yes, I know it would have to be it's own coin or whatever)

I believe that is what the NXT project is attempting to do.

It is a from scratch implementation of the ideas introduced by Bitcoin et al. They use Proof-of-Stake and claim to provide "built-in support for robust features such as a decentralized peer-to-peer exchange, voting system, messaging/chat, decentralized DNS, and options for instant transactions".


How to check if confirmation is done or not yet? After sending Bitcoin to any address, how can I check if the transaction has at least one confirmation?

Should I poll the transaction repeatedly or is there any event when confirmation is  made.

In order to see if the transaction has confirmed, you can search for it in any indexed transaction database. This can include Bitcoin Core running in -txindex mode, or a block explorer such as live.blockcypher.com or blockchain.info, for example. As soon as the transaction has been included in a block, it has 1 confirmation. If it is not found, or is still in the mempool, then it has either not propagated (failed validation checks), or has yet to be mined.


When do scripts executed? Can anyone explain when does a script executed exactly? There are several information about "how scripts are executed" but no information about "when".

The script is executed during the validation of a transaction by any full node which validates it. The script denotes the spending condition, so during the verification of a transaction the node will execute the script to ensure it passes successfully and does not violate any other rules (e.g. cleanstack)


Lightning LND - Send Payment Both Ways Within Same Channel Me and my friend are testing Raspibolt running LND 0.6 Beta. We noticed the following problem/limitation:

When I opened a channel with him, I could send him payments (via invoice) without any problems (direct connection). But when he tried to pay me (via invoice), the transaction tried to go through other nodes rather than going directly to my node. Then we closed the channel and tried the other way around. He opened a channel with my node and I could receive payments from him but I couldn't send him any payments directly. Transaction one again tried to go through other nodes.

Why is this happening?

The Problem here is the channel reserve. If you fund a channel all the bitcoin are on your side. At this point you can only pay. However let us assume you make a really small payment (below 1% of the channel capacity) your channel partner can't pay you back on that channel. After establishment lightning channels are required to keep at least 1% of the capacity on their side. If it was less it would incentivice the person owning no or only little liquidity to breach to protocol an publish and old channel state. Since the punishment would do basically no other harm then having a channel closed.

I suspect this is what happened between your two nodes. Try to balance the channel a little bit more by sending over 10% of your funds and sending back 5%. if that does work then we found the problem.


How many BTC have been paid in fees, in total? Is there a graph or some data points for the total BTC paid in fees?

I'm interested in total BTC as % of the issued BTC at various points in time as well.

https://www.blockchain.com/en/charts it's for you. In addition to being graphs of any kind, if you scroll to the bottom of the page you will find the Total Transaction Fees chart.

The total as of 2019-08-15 was 66967,60 BTC or 0.37% of the total coins in circulation on that day.


Let receivers pay transaction fees I want my customers to pay transaction fees. The only helpful but incomplete answer I have found so far is from here:

  You can create a transaction which spends the output to yourself, attaching a fee to that transaction. In order for miners to grab the transaction fee on that transaction, they would have to also mine the original transaction.

I have some experience of calling bitcoind methods using JSON. With these assumptions:

my account: "my"
receiver's address: "123..zyz"
coins to be sent: 0.001
transaction fee: (unpredictable)

my customer will receive 0.0008 coins if the transaction fee is 0.0002 in this case.

Am I supposed to first call method sendfrom like below?

sendfrom("my","123..zyz",0.001)

Then how do I determine the transaction fee? How do I charge the transaction fee to the receiver?
Would kind soul please provide me the detail answer with complete list of calls to Original Bitcoin client/API calls?

For precise calculations consider using raw transactions. Then you have to decide how this transaction fee will be calculated. For single output transactions it's clear, you deduct the tx fee from the receiving amount, although for some micro-payments this is not possible as the tx fee might be bigger than the actual payout amount. Batching your outgoing payments (pay many outputs in a single tx) will help reduce the transaction fees for your customers but in this case you have to decide who pays what. The tx fee is what is left if you deduct your outputs total amount (change included in that) from your inputs total amount. You can also chose to charge a flat fee per tx which is less precise but more transparent for your clients and easier for your calculations.


With just standard desktop or laptop, is it possible to mine obscure altcoins in the hope that one of them will take off? So just from the listing at coinmarketcap.com, there seems to be 954 cryptocurrencies right now. I imagine it's a bit like a startup, in that most of them will not survive.

It's too late to mine the big ones - like bitcoins, ethereum and litecoins - you probably need dedicated rigs with ASIC to mine them. But is it possible to just mine the smaller ones? The ones that are in the beginning stages in the hope that maybe one day they will take off? Would it be like mining bitcoin in 2009?

Yes, it is possible. Most altcoins are setup with low enough difficulty that you can CPU or GPU mine them, like you could with Bitcoin in the early days. However there are so many of these small obscure altcoins and almost all of them are just useless clones of some other coin or pump and dump scams, so you are likely going to just end up wasting electricity.


Error generate new block with signet test I have tried to test signet to generate new block but it is showed message as below:
bicoin-cli -signet -generate 1
ERROR: ProcessNewBlock: AcceptBlock FAILED (bad-signet-blksig, signet block signature validation failure)

You can't create blocks yourself for the global signet; it requires signatures by the parties running that signet.
You can create your own signet, though, where you yourself are the signer. The tooling around this is still a work in progress, as far as I know.


What keeps someone from creating a malicious wallet app? What keeps a person or company from creating an app like Armory but if you select "import or restore wallet" just emailing them your wallet key after you enter it and draining your account?

Answer: Nothing

Even with the most secure system, you're still trusting their developers.

Remember, secure encryption is not cracked, it's bypassed.


BIP 32 child key derivation "stops working" after a certain index (i) Here's my code to get a child public key from a parent HD key. I adapted it from freedomnode:

  public function address_from_master_pub($path = '0/0') {
    if ($this->xpub === NULL && $this->ypub === NULL && $this->zpub === NULL) {
      throw new Exception("XPUB, YPUB or ZPUB key is not present!");
    }

    $adapter = Bitcoin::getEcAdapter();
    $slip132 = new Slip132(new KeyToScriptHelper($adapter));
    $registry_classname = 'BitWasp\\Bitcoin\\Network\\Slip132\\'.$this->network_name.'Registry';
    $bitcoin_prefixes = new $registry_classname();

    if ($this->xpub !== NULL) {
      $pubPrefix = $slip132->p2pkh($bitcoin_prefixes);
      $pub = $this->xpub;
    } else if ($this->ypub !== NULL) {
      $pubPrefix = $slip132->p2shP2wpkh($bitcoin_prefixes);
      $pub = $this->ypub;
    } else if ($this->zpub !== NULL) {
      $pubPrefix = $slip132->p2wpkh($bitcoin_prefixes);
      $pub = $this->zpub;
    }

    $config = new GlobalPrefixConfig([
      new NetworkConfig($this->network, [
        $pubPrefix,
      ])
    ]);

    $serializer = new Base58ExtendedKeySerializer(
      new ExtendedKeySerializer($adapter, $config)
    );

    $key = $serializer->parse($this->network, $pub);
    $child_key = $key->derivePath($path);

    return $child_key->getAddress(new AddressCreator())->getAddress();
  }

If I use it for index 0 or 1 or 2 (paths 0/0, 0/1, 0/2), it works fine in the sense that if I send bitcoin to that address, I can see the transaction on the public blockchain under the parent xpub on blockchain.com and it shows the funds. Plus, the child addresses which I generate match what shows up in Mycelium HD account receiving address.

But when I used index 243 (thus creating a path of 0/243 it didn't show up on the receiving end (under that xpub) even though it showed up on my sending end as a confirmed transaction. That path 0/243 generated a valid bitcoin address, but it didn't show up under that xpub on blockchain.com even after it was confirmed.

What's the rule involved? If i > some limit it no longer works? Or if I use an index "out of order" it doesn't work? Or something else, like Mycelium stopping recognizing child addresses past a certain index (i) and really the fundsa safa just under a higher level new HD xpub? I used the same code to generate all the child addresses for i = 0, 1, 2, and 243.

Mycelium HD is BIP 44 compliant. As specified by BIP 44, the address gap limit is 20. This means that after 20 indexes of unused addresses, the wallet expects that no more addresses are used beyond that point. Therefore if you send funds to an address with a gap of more than 20 indexes between the last used address, the wallet software will not check if that address has received any funds.


What was the first official BTC miner software? I know that the first and official wallet is bitcoin-qt. This wallet has code here: https://github.com/bitcoin/bitcoin

What was the first official miner software? I understand that bitcoin-qt never use as miner software. Where is official code of miner software?

The first official mining software was Bitcoin Core (then known simply as Bitcoin, later bitcoin-qt), and it still serves as a reference mining implementation, making it the "official" miner. See its miner.cpp file, for example.

Bitcoin Core uses your CPU to mine. Mining eventually moved to GPUs and ASICs, so that mining on a CPU is practically pointless right now. In that sense, you should never use Bitcoin Core as mining software. But it still is mining software.