static void Main(string[] args) { Console.WriteLine("Ondrej Balas - Building a Blockchain"); Console.WriteLine("Twitter: @ondrejbalas"); Console.WriteLine("Website: https://ondrejbalas.com"); Console.WriteLine("Github: https://github.com/ondrejbalas/blockchain"); Console.WriteLine(); Console.WriteLine(); var blockchain = new Chain(); // Create the blockchain blockchain.AddGenesisBlock(); // Add the genesis block var genesisBlock = (blockchain.LastBlock as GenesisBlock); var pub1 = genesisBlock.Transactions.Single().Recipients.Single().Address; var priv1 = genesisBlock.SpendKey; // Get the genesis spend key (private key needed to spend coins from the genesis transaction) // Make a key for ourselves so we can send coins to it. CryptoProvider.GenerateKeyPair(out byte[] myPrivateKey, out byte[] myPublicKey); // Make a couple blocks var block1 = new Block(blockchain.LastBlock); var b1tx1 = new Transaction() { SourceAddress = pub1, Recipients = new List <TransactionTarget>() { new TransactionTarget() { Address = myPublicKey, Amount = 50m } } }; b1tx1.Sign(priv1); // Comment this line and the transaction will be rejected by the blockchain. block1.Transactions.Add(b1tx1); blockchain.AddBlock(block1); var ledger = blockchain.GetLedger(); ledger.Print(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Ondrej Balas - Building a Blockchain"); Console.WriteLine("Twitter: @ondrejbalas"); Console.WriteLine("Website: https://ondrejbalas.com"); Console.WriteLine("Github: https://github.com/ondrejbalas/blockchain"); Console.WriteLine(); Console.WriteLine(); Blockchain = new Chain(); // Create the blockchain Blockchain.AddGenesisBlock(); // Add the genesis block var genesisBlock = (Blockchain.LastBlock as GenesisBlock); var genesisAddress = genesisBlock.Transactions.Single().Recipients.Single().Address; var genesisSpendKey = genesisBlock.SpendKey; // Get the genesis spend key (private key needed to spend coins from the genesis transaction) Miner.StartMining(Blockchain, 1); Console.ReadLine(); }