- BLOCKCHAIN
- SMART-CONTRACT
Node
A basic node which cannot create a block.
var node = new EndpointNode();
// There's no `Start` method in `EndpointNode`.
Miner
You can operate mining node if you want to create a block and get mining rewards. Miner node will consume lots of CPU resources.
var node = new Miner();
node.Start();
Connect to peer
node.peers.AddPeer("ws://localhost:9916");
Current block (last confirmed block)
var block = node.chain.currentBlock;
var blockNo = block.blockNo;
var nonce = block.nonce; // solution
var difficulty = block.difficulty; // a difficulty number used to mine this block.
var merkleRootHash = block.merkleRootHash;
Retrive balance
var currentBalance = node.chain.GetBalance("ADDRESS");
var balanceAtSpecificBlock = node.chain.GetBalanceInBlock("ADDRESS", "BLOCK_HASH");
Deploy
var tx = node.wallet.CreateDeployTransaction("PROGRAM", "CTOR_SIGNATURE");
var contractAddress = tx.receiverAddr;
node.SendTransaction(tx);
Call method
var tx = node.wallet.CreateCallTransaction(
contractAddress, "METHOD_SIGNATURE",
new object[] { 10, 20 });
node.SendTransaction(tx);
Read field data
var val = node.chain.GetPublicField(contractAddress, "FIELD_SIGNATURE");
Import and Export
// Exports wallet data (this also includes PRIVATE-KEY)
var json = node.wallet.Export();
node.wallet.Import(json);
Retrive balance
var currentBalance = node.wallet.GetBalance();
var balanceAtSpecificBlock = node.wallet.GetBalanceInBlock("BLOCK_HASH");
Create a signed transaction
node.wallet.CreateSignedPaymentTransaction("RECEIVER_ADDR", VALUE_AMOUNT);