This is a project that I try to build a blockchain by myself.
Using go lang to build a blockchain.
git clone https://github.com/weiawesome/block-chain_go.git
(Ensure the computer have been installed go) (Ensure the mongodb is working)
go run main.go
- Success to build a node in 127.0.0.1:8080
//This mean the miner's node address
NodeAddr := "127.0.0.1:8080"
//This mean can connect to other node
NodeAddresses := []string{}
//This mean the mongodb's address
DbAddress:="localhost:27017"
//This mean the miners(goroutines) to mine.
Miners := 1
Make a mongodb container and port-forward to localhost
docker run --name mongodb -p 27017:27017 -d mongo
//This mean the miner's node address(choose another port)
NodeAddr := "127.0.0.1:8081"
//This mean can connect to other node(choose exist node)
NodeAddresses := []string{"127.0.0.1:8080"}
//This mean the mongodb's address(choose db in other port)
DbAddress:="localhost:27018"
- Success to connect with 127.0.0.1:8080
- Success to build and update the database
- Success to build a node in 127.0.0.1:8081 and connect with 127.0.0.1:8080
(Ensure the Miners is working)
go run api_block_get_by_block_hash.go
- Success to get the block with specific block hash
Edit the api_block_get_by_block_hash.go
//This is the query block_hash
var BlockHash string
BlockHash = "BlockHash"
//This is the connect node address
ConnectAddr:="127.0.0.1:8080"
go run api_block_get_by_block_height.go
- Success to get the block which block height equal to 0(Genesis block)
Edit the api_block_get_by_block_height.go
//This is the query block_height
var BlockHeight int64
BlockHeight = 0
//This is the connect node address
ConnectAddr := "127.0.0.1:8080"
go run api_block_get_last.go
- Success to get latest block
Edit the api_block_get_last.go
//This is the connect node address
ConnectAddr := "127.0.0.1:8080"
(Ensure the Miners is working)
go run api_transaction_submit.go
- Success to submit a transaction into blockchain
- Success to show the transaction's detail information
Edit the api_transaction_submit.go
//This is UTXOHash to prove the asset
UTXOHash = "UTXOHash"
//This is to use with UTXOHash to prove the asset
Index = 0
//This is the address the transaction transfer
Address = "Address"
//This is the amount the transaction transfer
Amount = 0
//This is the fee to miner in the transaction
Fee = 0
//This is public key for sender
PublicKey = "PublicKey"
//This is private key for sender
PrivateKey = "PrivateKey"
//This is the connect node address
ConnectAddr := "127.0.0.1:8080"
# submit a transaction with specific address
go run api_transaction_submit_free.go
# submit a transaction with generating an address
go run api_transaction_submit_free_random_addr.go
- Success to submit a transaction into blockchain
- Success to gain the free asset
Edit the api_transaction_submit_free.go
//This is the amount give to the address
var Amount float64
Amount=0
//This is the address to be given
var Addr string
Addr = "Address"
//This is the connect node address
ConnectAddr := "127.0.0.1:8080"
Edit the api_transaction_submit_free_random_addr.go
//This is the amount give to the address
var Amount float64
Amount=0
//This is the connect node address
ConnectAddr := "127.0.0.1:8080"