Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Latest commit

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

LaksaCsharp

LaksaCsharp -- Zilliqa Blockchain C# Library

The project is still under development.

Quick Start

More docs can be found in https://apidocs.zilliqa.com/

Generate large amount of addresses

usingLaksaCsharp.Crypto;usingLaksaCsharp.Utils;usingOrg.BouncyCastle.Math;usingSystem;namespaceExample{classProgram{staticvoidMain(string[]args){intn=0;while(n<100){Console.WriteLine("--------------------------");Console.WriteLine("generate nth keypair:");ECKeyPairkeyPair=KeyTools.GenerateKeyPair();BigIntegerprivateInteger=keyPair.PrivateKey;BigIntegerpublicInteger=keyPair.PublicKey;Console.WriteLine("private key is: "+ByteUtil.ByteArrayToHexString(privateInteger.ToByteArray()));Console.WriteLine("public key is: "+ByteUtil.ByteArrayToHexString(publicInteger.ToByteArray()));Console.WriteLine("address is: "+KeyTools.GetAddressFromPublicKey(ByteUtil.ByteArrayToHexString(publicInteger.toByteArray())));}}}}

Validate an address

usingLaksaCsharp.Utils;usingSystem;namespaceExample{classProgram{staticvoidMain(string[]args){stringaddress="2624B9EA4B1CD740630F6BF2FEA82AAC0067070B";boolisAddress=Validation.IsAddress(address);Console.WriteLine("is address: "+isAddress);}}}

Validate checksum address

usingLaksaCsharp.Utils;usingSystem;namespaceExample{classProgram{staticvoidMain(string[]args){stringchecksumAddress="0x4BAF5faDA8e5Db92C3d3242618c5B47133AE003C";boolisChecksumAddress=Validation.IsValidChecksumAddress(checksumAddress);Console.WriteLine("is checksum address: "+isChecksumAddress);}}}

Transaction operation (include construct transaction, calculate transaction fee, do serialization, sign a transaction, broadcast)

usingLaksaCsharp.Account;usingLaksaCsharp.Contract;usingLaksaCsharp.Jsonrpc;usingLaksaCsharp.Transaction;usingLaksaCsharp.Utils;usingOrg.BouncyCastle.Math;usingSystem;usingSystem.Collections.Generic;namespaceExample{classProgram{staticvoidMain(string[]args){Walletwallet=newWallet();stringptivateKey="e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930";// Populate the wallet with an accountstringaddress=wallet.AddByPrivateKey(ptivateKey);Console.WriteLine("address is: "+address);HttpProviderprovider=newHttpProvider("https://api.zilliqa.com");//get balanceBalanceResultbalanceResult=provider.GetBalance(address).Result;Console.WriteLine("balance is: "+balanceResult.Balance);//construct non-contract transactionTransactiontransaction=newTransaction();transaction.Version=Wallet.Pack(333,8).ToString();transaction.ToAddr="4baf5fada8e5db92c3d3242618c5b47133ae003c";transaction.SenderPubKey="0246e7178dc8253201101e18fd6f6eb9972451d121fc57aa2a06dd5c111e58dc6a";transaction.Amount="10000000";transaction.GasPrice="1000000000";transaction.GasLimit="1";transaction.Code="";transaction.Data="";transaction.Provider=newHttpProvider("https://dev-api.zilliqa.com/");//sign transactiontransaction=wallet.Sign(transaction);Console.WriteLine("signature is: "+transaction.Signature);//broadcast transactionCreateTxResultresult=TransactionFactory.CreateTransaction(transaction);Console.WriteLine(result);//hello-world contractStringcode="scilla_version 0\n"+"\n"+" (* HelloWorld contract *)\n"+"\n"+" import ListUtils\n"+"\n"+" (***************************************************)\n"+" (* Associated library *)\n"+" (***************************************************)\n"+" library HelloWorld\n"+"\n"+" let one_msg =\n"+" fun (msg : Message) =>\n"+" let nil_msg = Nil {Message} in\n"+" Cons {Message} msg nil_msg\n"+"\n"+" let not_owner_code = Int32 1\n"+" let set_hello_code = Int32 2\n"+"\n"+" (***************************************************)\n"+" (* The contract definition *)\n"+" (***************************************************)\n"+"\n"+" contract HelloWorld\n"+" (owner: ByStr20)\n"+"\n"+" field welcome_msg : String = \"\"\n"+"\n"+" transition setHello (msg : String)\n"+" is_owner = builtin eq owner _sender;\n"+" match is_owner with\n"+" | False =>\n"+" msg = {_tag : \"TransactionOperation\"; _recipient : _sender; _amount : Uint128 0; code : not_owner_code};\n"+" msgs = one_msg msg;\n"+" send msgs\n"+" | True =>\n"+" welcome_msg := msg;\n"+" msg = {_tag : \"TransactionOperation\"; _recipient : _sender; _amount : Uint128 0; code : set_hello_code};\n"+" msgs = one_msg msg;\n"+" send msgs\n"+" end\n"+" end\n"+"\n"+"\n"+" transition getHello ()\n"+" r <- welcome_msg;\n"+" e = {_eventname: \"getHello()\"; msg: r};\n"+" event e\n"+" end";List<Values>init=newList<Values>(){newValues(){Type="Uint32",Value="0",VName="_scilla_version"},newValues(){Type="ByStr20",Value="0x9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a",VName="owner"},};ContractFactoryfactory=newContractFactory(){Provider=newHttpProvider("https://api.zilliqa.com/"),Signer=wallet};Contractcontract=factory.NewContract(code,(Values[])init.ToArray(),"");DeployParamsdeployParams=newDeployParams(){GasLimit="10000",GasPrice="1000000000",SenderPubKey="0246e7178dc8253201101e18fd6f6eb9972451d121fc57aa2a06dd5c111e58dc6a",Version=Wallet.Pack(2,8).ToString()};//deploy contract, this will take a while to track transaction util it been confirmed or failedTuple<Transaction,Contract>deployResult=contract.Deploy(deployParams,300,3);Console.WriteLine("result is: "+deployResult);Console.WriteLine("cumulative gas is: "+deployResult.Item1.Receipt.Cumulative_gas);//calculate transaction feestringtransactionFee=newBigInteger(deployResult.Item1.Receipt.Cumulative_gas).Multiply(newBigInteger(deployResult.Item1.GasPrice)).ToString();Console.WriteLine("transaction fee is: "+transactionFee);}}}

Know a smart contract deposit

usingLaksaCsharp.BlockChain;usingLaksaCsharp.Jsonrpc;usingSystem;usingSystem.Collections.Generic;usingSystem.Threading;namespaceExample{classProgram{staticvoidMain(string[]args){HttpProviderclient=newHttpProvider("https://api.zilliqa.com/");stringlastEpoch=client.GetNumTxnsTxEpoch().Result;List<State>lastStateList=client.GetSmartContractState("D6606D02DFF929593312D8D0D36105E376F95AA0").Result;Console.WriteLine("last epoch is "+lastEpoch);Console.WriteLine("last state:"+lastStateList);intn=0;while(true){stringepoch=client.GetNumTxnsTxEpoch().Result;Console.WriteLine(n+"th current epoch is: "+epoch);if(lastEpoch!=epoch){Console.WriteLine("epoch hash changed");List<State>stateList=client.GetSmartContractState("D6606D02DFF929593312D8D0D36105E376F95AA0").Result;Console.WriteLine("last state: "+lastStateList);Console.WriteLine("current state: "+stateList);lastEpoch=epoch;lastStateList=stateList;}Thread.Sleep(3000);n+=1;}}}}

Account API

  • FromFile
  • ToFile

Wallet API

  • CreateAccount
  • AddByPrivateKey addByKeyStore
  • Remove
  • SetDefault
  • SignTransaction (default account)
  • SignTransactionWith (specific account)

TransactionFactory Transaction

  • SendTransaction
  • TrackTx
  • Confirm
  • IsPending isInitialised isConfirmed isRejected

ContractFactory Contract

  • Deploy
  • Call
  • IsInitialised isDeployed isRejected
  • GetState
  • GetAddressForContract

Crypto API

  • GetDerivedKey (PBKDF2 and Scrypt)
  • GeneratePrivateKey
  • Schnorr.sign
  • Schnorr.verify
  • GetPublicKeyFromPrivateKey
  • GetPublicKeyFromPrivateKey
  • GetAddressFromPublicKey
  • GetAddressFromPrivateKey
  • EncryptPrivateKey
  • DecryptPrivateKey

JSON-RPC API

Blockchain-related methods

  • GetNetworkId
  • GetBlockchainInfo
  • GetShardingStructure
  • GetDsBlock
  • GetLatestDsBlock
  • GetNumDSBlocks
  • GetDSBlockRate
  • GetDSBlockListing
  • GetTxBlock
  • GetLatestTxBlock
  • GetNumTxBlocks
  • GetTxBlockRate
  • GetTxBlockListing
  • GetNumTransactions
  • GetTransactionRate
  • GetCurrentMiniEpoch
  • GetCurrentDSEpoch
  • GetPrevDifficulty
  • GetPrevDSDifficulty

Transaction-related methods

  • CreateTransaction
  • GetTransaction
  • GetRecentTransactions
  • GetTransactionsForTxBlock
  • GetNumTxnsTxEpoch
  • GetNumTxnsDSEpoch
  • GetMinimumGasPrice

Contract-related methods

  • GetSmartContractCode
  • GetSmartContractInit
  • GetSmartContractState
  • GetSmartContracts
  • GetContractAddressFromTransactionID

Account-related methods

  • GetBalance

Validation

  • IsAddress
  • IsPublicjKey
  • IsPrivateKey
  • IsSignature

Util

  • ByteArrayToHexString
  • HexStringToByteArray
  • GenerateMac
  • IsByteString
  • EncodeTransactionProto
  • ToChecksumAddress
  • IsValidChecksumAddress

About

Zilliqa Blockchain C# Library

Resources

Stars

4 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages