RNGeth makes using Go-Ethereum ( Official Go implementation of the Ethereum protocol ) with React Native simple.
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,....
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.
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.
Go-Ethereum is one of the three original implementations (along with C++ and Python) of the Ethereum protocol. It is written in Go
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.
- Android
- iOS
$ npm i react-native-geth --save
$ react-native link react-native-geth
cd ios/
Pod init
Edit your Podfile
// Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'YourReactNativeApp' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Geth', '1.8.3'
end
pod install
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 networkID = 1
// Chain ID
const chainID = 17
// genesis.json
const genesis = `{
"config": {
"chainId": ${chainID},
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "20",
"gasLimit": "10000000",
"alloc": {}
}`
const config = {
"networkID": networkID, // --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)
}
}
- Geth
- start [android, ios]
- stop [android, ios]
- newAccount [android, ios]
- setAccount
- getAddress
- balanceAccount
- balanceAt
- syncProgress
- subscribeNewHead
- updateAccount
- deleteAccount
- exportKey
- importKey
- listAccounts [android, ios]
- createAndSendTransaction
- suggestGasPrice
- getPendingNonce
- sendTransaction [ios]
- sendSignedTransaction [ios]
- signTransaction [ios]
- getBalance [ios]
- getPeersInfo [ios]
Geth object
Parameters
config
Objectconfig.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 fileconfig.nodeDir
string Data directory for the databases and keystoreconfig.keyStoreDir
string Directory for the keystore (default = inside the datadir)config.enodes
string Comma separated enode URLs for P2P discovery bootstrap
Start creates a live P2P node and starts running it.
Returns Boolean return true if started.
Terminates a running node along with all it's services.
Returns Boolean return true if stopped.
Create a new account with the specified encryption passphrase.
Parameters
passphrase
String Passphrase
Returns Object return new account object
Sets the default account at the given index in the listAccounts.
Parameters
accID
Number index in the listAccounts
Returns Boolean return true if sets.
Retrieves the address associated with the current account.
Returns String return address..
Returns the wei balance of the current account.
Returns String return balance.
Returns the wei balance of the specified account.
Parameters
address
String Address of account being looked up.
Returns String Return balance.
Retrieves the current progress of the sync algorithm.
Returns Object Return object sync progress or null
Subscribes to notifications about the current blockchain head
Returns Boolean Return true if subscribed
Changes the passphrase of current account.
Parameters
Returns Boolean Return true if passphrase changed
Deletes the key matched by current account if the passphrase is correct.
Parameters
passphrase
string
Returns Boolean Return true if account deleted
Exports as a JSON key of current account, encrypted with new passphrase.
Parameters
Returns String Return key
Stores the given encrypted JSON key into the key directory.
Parameters
Returns Object Return account object
Returns all key files present in the directory.
Returns Array Return array of accounts objects
Create and send transaction.
Parameters
passphrase
String Passphrasenonce
Number Account nonce (use -1 to use last known nonce)toAddress
String Address destinationamount
Number AmountgasLimit
Number Gas limitgasPrice
Number Gas pricedata
Number
Returns String Return transaction
Retrieves the currently suggested gas price to allow a timely execution of a transaction.
Returns Double Return suggested gas price
Retrieves this account's pending nonce. This is the nonce you should use when creating a transaction.
Returns Double Return nonce
Sends a transaction.
Parameters
Returns String Return transaction
Sends a signed transaction.
Parameters
transaction
Object Signed Transaction object
Returns String Return transaction
Signs a transaction.
Parameters
Returns String Return transaction
Gets balance of an address.
Parameters
address
String Hex address string
Returns BN Wei balance
Gets all connected peers information in an array.
Parameters
JSON Object
{
caps: "[eth/62 eth/63 les/1 les/2]",
id: "3afdfd40713a8b188a94e4c7a9ddc61bc6ef176c3abbb13d1dd35eb367725b95329a7570039044dbffa49c50d4aa65f0a1f99ee68e46b8e2f09100d11d4fc85a",
localAddress: "192.168.0.2:63235",
name: "Geth/v1.8.3-stable-329ac18e/linux-amd64/go1.10"
remoteAddress: "31.19.176.208:30303"
}
React Native Geth is released under the MIT license