GithubHelp home page GithubHelp logo

ykankaya / example-eth-wallet-in-dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkirsteins/example-eth-wallet-in-dotnet

0.0 1.0 0.0 367 KB

An example wallet for Ethereum, accompanying this Medium article: https://medium.com/@jkirsteins/writing-an-ethereum-wallet-for-fun-e82a05322ae2

License: MIT License

C# 100.00%

example-eth-wallet-in-dotnet's Introduction

Wallet Screnshot

Demo Ethereum Wallet

This is a barebones Ethereum wallet, which supports:

  • generating a new secp256k1 private key
  • saving and loading its state from JSON
  • synchronizing with Infura's Rinkeby node
  • sending transactions

Values denominated in wei are represented using the BigInteger type.

Values denominated in ether (used in interaction with the user) are represented using the decimal type.

This wallet was written to accompany this Medium article: Writing an Ethereum Wallet for Fun.

Dependencies

The main dependency is the Nethereum library, which handles key generation, and Ethereum JSON RPC function calls.

Structure

The Wallet is a partial class split across 3 files:

  • Wallet.SerializableProperties.cs contains the properties that will be saved to/loaded from JSON
  • Wallet.LoadingAndSaving.cs contains code that pertains to wallet generation, loading, and saving
  • Wallet.EthereumInteraction.cs contains code that interacts with the Infura Rinkeby node using the Nethereum library

The Wallet - upon creation - will query the Infura Rinkeby node for the latest known block, and store it as the last known block.

Afterwards, it can be synchronized - every synchronization action will load blocks between the last known block of the wallet (stored in the JSON file) and the last known block as reported by the Infura's Rinkeby node. For every block it will download every transaction, and look if from/to values correspond to our wallet's address. If they do, the found transactions will be stored in the JSON file.

The application is structured as a CLI application, which presents a menu with the available options:

  • listing known transactions (found by the synchronization action, and stored in the local JSON file)
  • sending a transaction
  • performing a new synchronization action

The file Program.cs mainly deals with the UI, and is pretty boring.

ConsoleEx is a class which contains convenience methods for prompting values from the user using the command-line (e.g. helpers for querying for decimals, BigIntegers, optional BigIntegers and Ethereum addresses)

Extensions

There are a couple of extensions:

  • StringExtensions.cs contains code for verifying that a string is a hex string representing a valid 20-byte value. This is used for verifying that the user entered a valid Ethereum address, when sending a transaction.
  • DecimalExtensions.cs and BigIntegerExtensions.cs contain code for converting between wei and ether denominated values (BigIntegers and decimals respectively).

example-eth-wallet-in-dotnet's People

Contributors

jkirsteins avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.