Git Product home page Git Product logo

react-native-geth's Introduction

React Native Geth

Ethereum

Description

RNGeth makes using Go-Ethereum ( Official Go implementation of the Ethereum protocol ) with React Native simple.

What is react-native-geth?

Is a React-Native module allow you to build dApps (Decentralized Applications) transforms your mobile device into a light client node on the Ethereum Network and enables you to easily access Ethereum’s entire ecosystem. Interacting with Smart Contracts, make payment,....

What is Blockchain?

A blockchain, originally block chain, is a continuously growing list of records, called blocks, which are linked and secured using cryptography. Each block typically contains a hash pointer as a link to a previous block, a timestamp and transaction data. By design, blockchains are inherently resistant to modification of the data. It is "an open, distributed ledger that can record transactions between two parties efficiently and in a verifiable and permanent way". For use as a distributed ledger, a blockchain is typically managed by a peer-to-peer network collectively adhering to a protocol for validating new blocks. Once recorded, the data in any given block cannot be altered retroactively without the alteration of all subsequent blocks, which requires collusion of the network majority.

What is Ethereum?

Ethereum is a decentralized platform that runs smart contracts, applications that run exactly as programmed without possibility of downtime, censorship, fraud or third party interference.

What is Go Ethereum?

Go-Ethereum is one of the three original implementations (along with C++ and Python) of the Ethereum protocol. It is written in Go

What is Smart Contract?

A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract. Smart contracts allow the performance of credible transactions without third parties. These transactions are trackable and irreversible.

Supported platforms

  • Android
  • iOS (Need PR)

Initial Setup

$ npm i react-native-geth --save

$ react-native link react-native-geth

JavaScript Usage

import Geth from 'react-native-geth';

// Ethereum Network Frontier
const Eth = async () => {
  const geth = new Geth()
  // start node
  const start = await geth.start()

  if (start) {
    console.log('Start :', start)
    // stop node
    const stop = await geth.stop()
    console.log('Stop :', stop)
  }
}

// Custom Ethereum Network
const PrivateEth = async () => {
  // Network ID
  const chainID = 17
  // genesis.json
  const genesis = `{
    "config": {
      "chainId": ${chainID},
      "homesteadBlock": 0,
      "eip155Block": 0,
      "eip158Block": 0
    },
    "difficulty": "20",
    "gasLimit": "10000000",
    "alloc": {}
  }`

  const config = {
    "chainID": chainID, // --networkid / Network identifier (integer, 0=Olympic (disused), 1=Frontier, 2=Morden (disused), 3=Ropsten) (default: 1)
    "maxPeers": 0, // --maxpeers / Maximum number of network peers (network disabled if set to 0) (default: 25)
    "genesis": genesis, // genesis.json file
    "nodeDir": ".private-ethereum", // --datadir / Data directory for the databases and keystore
    "keyStoreDir": "keystore", // --keystore / Directory for the keystore (default = inside the datadir)
    "enodes": "enode://XXXX@X[::]:XXXX" // --bootnodes / Comma separated enode URLs for P2P discovery bootstrap
  }

  const geth = new Geth(config)
  // start node
  const start = await geth.start()

  if (start) {
    console.log('Start :', start)
    const stop = await geth.stop()
    console.log('Stop :', stop)
  }
}

Documentation :

Table of Contents

Geth

Geth object

Parameters

  • config Object
    • config.chainID number Network identifier (integer, 0=Olympic (disused), 1=Frontier, 2=Morden (disused), 3=Ropsten) (default: 1)
    • config.maxPeers number Maximum number of network peers (network disabled if set to 0) (default: 25)
    • config.genesis string genesis.json file
    • config.nodeDir string Data directory for the databases and keystore
    • config.keyStoreDir string Directory for the keystore (default = inside the datadir)
    • config.enodes string Comma separated enode URLs for P2P discovery bootstrap

start

Start creates a live P2P node and starts running it.

Returns Boolean return true if started.

stop

Terminates a running node along with all it's services.

Returns Boolean return true if stopped.

newAccount

Create a new account with the specified encryption passphrase.

Parameters

  • passphrase String Passphrase

Returns Object return new account object

setAccount

Sets the default account at the given index in the listAccounts.

Parameters

  • accID Number index in the listAccounts

Returns Boolean return true if sets.

getAddress

Retrieves the address associated with the current account.

Returns String return address..

balanceAccount

Returns the wei balance of the current account.

Returns String return balance.

balanceAt

Returns the wei balance of the specified account.

Parameters

  • address String Address of account being looked up.

Returns String Return balance.

syncProgress

Retrieves the current progress of the sync algorithm.

Returns Object Return object sync progress or null

subscribeNewHead

Subscribes to notifications about the current blockchain head

Returns Boolean Return true if subscribed

updateAccount

Changes the passphrase of current account.

Parameters

  • oldPassphrase String Passphrase
  • newPassphrase String New passphrase

Returns Boolean Return true if passphrase changed

deleteAccount

Deletes the key matched by current account if the passphrase is correct.

Parameters

Returns Boolean Return true if account deleted

exportKey

Exports as a JSON key of current account, encrypted with new passphrase.

Parameters

  • creationPassphrase String Old Passphrase
  • exportPassphrase String New passphrase

Returns String Return key

importKey

Stores the given encrypted JSON key into the key directory.

Parameters

  • key String Passphrase
  • oldPassphrase String Old passphrase
  • newPassphrase String New passphrase

Returns Object Return account object

listAccounts

Returns all key files present in the directory.

Returns Array Return array of accounts objects

createAndSendTransaction

Create and send transaction.

Parameters

  • passphrase String Passphrase
  • nonce Number Account nonce (use -1 to use last known nonce)
  • toAddress String Address destination
  • amount Number Amount
  • gasLimit Number Gas limit
  • gasPrice Number Gas price
  • data Number

Returns String Return transaction

suggestGasPrice

Retrieves the currently suggested gas price to allow a timely execution of a transaction.

Returns Double Return suggested gas price

getPendingNonce

Retrieves this account's pending nonce. This is the nonce you should use when creating a transaction.

Returns Double Return nonce


Press the "Watch" button to get updates. Do not forget the "Star" button 😀


React Native Geth is released under the MIT license

react-native-geth's People

Contributors

marekolszewski avatar ysnksy avatar

Watchers

 avatar  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.