Welcome! This is my personal blog about Web technologies, software development, open source and other related topics
The ideas and opinions expressed here are solely mine and don't represent those of others, either individuals or companies.The code snippets or references to software products or analogous are to be used without any warranty of any kind. If you enjoy the content, feel free to share it and re-use it as long as you provide a link to the original post.
By default Bitcoin Core builds a database containing only the transactions for the user’s wallet.
Wallet transactions can be retireved using JSON RPC API gettransaction command.
But if you want to retrieve any transaction within the node use command getrawtransaction. This command will search transactions in the index.
bitcoin.conf fileset txindex–
Bitcoin daemon or GUI uses conf file to load settings. On the first bitcoind run it will ask to create a config file.
Set txindex=1 in the config file before running the daemon. If the indexing is enabled the bitcoin daemon then should start synching the blocks and index.
bitcond -reindex option
If the txindex is not set in config before the first run and if later you want to index the database use -reindex option.
Re-index should take a while. To improve perfromance disable -printtoconsole option
This installation is performed on freshly installed Ubuntu system.
sudo apt update
snap install bitcoin-core
This should install Bitcoin Core on Ubuntu machine-
But lets not use GUI for this and setup test node using Bitcoin Daemon.
Bitcoin daemon should be installed in root folder and the executable can be found on this path- /snap/bitcoin-core/141/bin
Use below command to find the version of the daemon-
bitcoin-core.daemon --version
Run command –
bitcoin-core.daemon
Here the last line its expecting a bitcoin.conf file in location- /home/sandy/snap/bitcoin-core/common/.bitcoin/bitcoin.conf. This oath might be different for you.
Create a bitcoin.conf file at this location and paste in following to configure bitcoin daemon to run in test node.
Set the chain=test
set path to blocksdir and datadir
set txindex=1 to index the transaction
Set rpcuser and rpcpassword to use JSON rpc api
server=1 tells Bitcoin-QT to accept JSON-RPC commands.
# [chain]
# Test Network.
chain=test
# [core]
# Specify a non-default location to store blockchain data.
blocksdir=/home/sandy/snap/bitcoin-core/common/.bitcoin
# Specify a non-default location to store blockchain and other data.
datadir=/home/sandy/snap/bitcoin-core/common/.bitcoin
# Options only for mainnet
[main]
# Options only for testnet
[test]
# Options only for regtest
[regtest]
txindex=1
server=1
rpcuser=your_rpc_user
rpcpassword=your_rpc_pwd
rpcallowip=*
-txindex Maintain a full transaction index, used by the getrawtransaction rpc call (default: 0)
-rpcpassword= Password for JSON-RPC connections
-rpcuser= Username for JSON-RPC connections
Run following command to run the daemon in test node. This will download the data which is around 29gb at the time of writing this blog.
This should now start the daemon and will check if the data is available, if not this should start download the blocks.
First it wll pre-Synchronize the block headers and then start Synchronizing headers. At the time of writing this blog there are around 2428000 blocks in test node.
Once synchronizing is complete it should start downloading and indexing blocks-
Here the height is the block it has synchronised and the progress. When the progress is near to 1 it will come to completion of synchronising the node.
In the above example 0000000000002f4ee789f0bd19066bccd78172ca71995505996fbff1a3341eac is a block hash
progress when near to 1 means it about to complete synchronising all blocks.
A new folder called testnet3 will be created in .bitcoin folder – This should be in user folder and not root folder.
For me it took less than 2 hours to sync all blocks.
2023-07-23T16:55:23Z UpdateTip: new best=0000000000000022020dfc2655e4489eb54a8ae306080a47d1fa0be46e0c43a8 height=2443382 version=0x31636000 log2_work=75.416383 tx=66092181 date='2023-07-23T16:40:35Z' progress=0.999999 cache=479.2MiB(3458766txo)
2023-07-23T16:56:04Z New outbound peer connected: version: 70015, blocks=2443382, peer=76 (block-relay-only)
2023-07-23T17:00:42Z Saw new header hash=0000000000001019c41ee044adf1c02d347ed52d875eefeb8e629f0a5baa4a8b height=2443383
2023-07-23T17:00:42Z [net] Saw new cmpctblock header hash=0000000000001019c41ee044adf1c02d347ed52d875eefeb8e629f0a5baa4a8b peer=3
2023-07-23T17:00:42Z UpdateTip: new best=0000000000001019c41ee044adf1c02d347ed52d875eefeb8e629f0a5baa4a8b height=2443383 version=0x29e7a000 log2_work=75.416383 tx=66092225 date='2023-07-23T17:00:37Z' progress=1.000000 cache=479.2MiB(3458790txo)
The last block to sync was 2443382
It also listens to any new block been created on chain- 2443383 which happened after 5 minutes. See highlighted.
This confirms that the blocks are indexed as the getrawtransaction looks for node and not your own wallet transaction.
How to get transaction details will put that in another blog.
Hope this helps to configure full test node on your system.
Performance–
To run the daemon blockonly option –
bitcoind -daemon -blocksonly
.By default, bitcoind relays transactions while you’re syncing and using -blocksonly turns that off. It probably won’t make a huge difference but should save you some bandwidth.
Increase dbcache
-dbcache= The default for this is 450. If you have 8GB of RAM, you could set this to 4096
At time when the Ganache tool is re-opened all the Transactions and Constracts are reset. Whilst deploying contract you might see the error –
ContractNotFound: No contract deployed at{address}
PS C:\Projects\Blockchain\Solidity\brownie_fundme> brownie run .\scripts\deploy.py --network ganache-local
INFO: Could not find files for the given pattern(s).
Brownie v1.19.0 - Python development framework for Ethereum
BrownieFundmeProject is the active project.
File "C:\Users\sandeep\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\_cli\__main__.py", line 64, in main
importlib.import_module(f"brownie._cli.{cmd}").main()
File "C:\Users\sandeep\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\_cli\run.py", line 45, in main
network.connect(CONFIG.argv["network"])
File "C:\Users\sandeep\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\main.py", line 55, in connect
p._load_deployments()
File "C:\Users\sandeep\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\project\main.py", line 370, in _load_deployments
contract = ProjectContract(self, build, build_json.stem)
File "C:\Users\sandeep\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 1305, in __init__
_DeployedContractBase.__init__(self, address, owner, tx)
File "C:\Users\sandeep\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 708, in __init__
raise ContractNotFound(f"No contract deployed at {address}")
ContractNotFound: No contract deployed at 0x7465E5ca8aFeFba39eFD83bd056ACAafa3d16646
Solution-
Delete all the files and folders in Deployment folder as closing the Ganache tool will reset contracts etc. the deployment folder has references to old contract.
Ganache is the development tool used to run local blockchain for Ethereum development.
Ganache can be used to deploy the contract to local Blockchain. Its a simutated environemnt like Javascript VM when developing on Remix. It helps spin up a local Blockchain.
Decentralised – Having no single point of authority
Transperancy and Flexibility
Speed and Effeciency
Security and Immutability
Removal of counterparty risk
Trust minimised agreements
Hybrid smart conrtract with Chain Link (Oracle)
Terms and Abbrevations used in Blockchain-
DAO’s – Decentralised Autonomous Organization’s
Testnet – are free and for testing smart contracts
Mainnet – cost money and are considered “live”
Faucet – is and application that gives us free test token, like free test Rinkeby Ethereum
Block Explorer – an application that allows us to “view” transactions that happen on a blockchain.
Gas – is a unit of computational measure. The more computation a transaction uses the more “gas” you have to pay for.
Every transaction that happens on-chain pays a “gas fee” to node operators.
The amount of “gas” used and how much you pay depends on how “computationally expensive” your transaction is.
Sending ETH to 1 address would be “cheaper” than sending ETH to 1,000 addresses.
Gwei (giga-wei) – denomination or a small unit of Ether 1 Ether is 1 billion Gwei. It is used to measure cost of transaction i.e. used in the Ethereum network to but and sell goods and services.
Gas – Measure of computation use
Gas Price – How much it costs per unit of gas.
Gas Limit – Max amount of gas in a transaction
Transaction Fee – Gas used X Gas Price i.e. 21,000 gas @ 1GWEI per gas =21,000 GWEI
Gas Price of Ehtereum fluctuates based on the demand of the blockchain. More perople using or want to make transactions, the higher the gas price and therefore the higher the transaction fees.
Gnesis Block – First block in a blockchain
Hash – Unique fixed length string to identify a piece of data
Hash Algorithm – A function or algorithm that computes data into a unique hash.
Mining – The precess of finding the “solution” to the blockchain “problem”. Node get paid for mining blocks.
Block – A list of transactions mined together
Nonce – A “number used once” to find the “solution” to the blockchain problem. It’s also used to define the transaction number for an account/address.
Public Key – Is derived from your private key. Anyone can “see” it, and user it, and user it to verify that a transaction came from you.
Private key – Only know to the keyholder, its used to “sign” transactions.
Elliptic Curve Digital Signature Algorithm (ECDSA) – generates public key using private key.
Signing Transactions – A “one way” process. Someone with a private key signs a transaction by their private key being hashed with their transaction data. Anyone can then verify this new transaction hash with your public key.
Node: Single instance in a decentralized network. Anyone can join the network. Blockchains are resilient. Blockchain nodes keep lists of the transactions that occur. They are immutable- nothing can corrupt them.
—Consensus – is the mechanism used to agree on the state of a blockchain.
Broken into 2 :-
— Chain Selection –
— Sybil Resistance – Proof of work. Block Author, defends on fake blockchains
— — PoW – Minners. Uses lot of electricity and is hence costly.
-Transaction Fees and Block Reward.- compete each other to find the answer to the problems. Whoever finds first get the transaction fees.
Sybil Attack – creates fake accounts to influence the network
51% attack –
Longest Chain Rule
– — PoS — Validators – nodes put up collateral as a sybil resistance mechanism. Uses less energy. Slightly less decentralised.
ABI– ApplicationBinary Interface- tells Solidity how it can interact with another contract. What functions can be called from the contract. Interfaces compile down to ABI.