rn-g8c-sdk
v1.0.1
Published
react native wallet sdk by namnh270
Downloads
4
Readme
WALLET SDK
Install package
- run
npm install rn-wallet-sdk-test
oryarn add rn-wallet-sdk-test
- To use this package, you will need to install React Native Nodeify
to use node core modules and npm modules that use them in your React Native app by the following command line
npm install rn-nodeify
oryarn add rn-nodeify
- run
rn-nodeify --install --hack
if you use npm, add--yarn
if you want to use yarn - run
cd ios && pod install && cd ..
to install package on iOS - you can run your project now
react-native run-ios
orreact-native run-android
API
Wallet
generateMnemonic()
- Returns:
- Success: mnemonic 24 words.
- Error: 'Generate mnemonic failed'.
- Returns:
generateWallet(mnemonic, password)
- Parameters:
- mnemonic: mnemonic 24 words.
- password: password for encrypting private key and mnemonic.
- Returns:
- Success: (Promise) wallet object with public key, address, encryption of mnemonic and encryption of private key.
- Error:
- 'Get address from public key failed'.
- 'Encrypt failed'.
- Others.
- Parameters:
encryptString(privateString, password)
- Parameters:
- privateString: private string will be encrypted.
- password: password will be used to when encrypting.
- Return :
- Success: encryption of private string with password.
- Error: 'Encrypt failed'.
- Parameters:
decryptString(cipherText, password)
- Parameters:
- cipherText: encryption of private string.
- password: password is used for decryption.
- Return :
- Success: decryption of cipherText with password.
- Error: 'Encrypt failed'.
- Parameters:
restoreWallet(mnemonic, password)
- Parameters:
- mnemonic: mnemonic passphrase will be used to restore wallet, examples:
abandon abandon ...
- password: password will be used to encrypt private key.
- mnemonic: mnemonic passphrase will be used to restore wallet, examples:
- Returns:
- Success: (Promise) wallet object with public key, address, encryption of mnemonic and encryption of private key.
- Error:
- 'Get address from public key failed'.
- 'Encrypt failed'.
- Others.
- Parameters:
getAddressFromPublicKey(publicKey)
- Parameters:
- publicKey: public key of wallet.
- Returns:
- Success: address from public key.
- Error: 'Get address from public key failed'.
- Parameters:
getPublicKeyOffline(privateKey, curveType)
- Parameters:
- privateKey: private key of wallet.
- curveType: type of curve algorithm.
- Returns:
- Success: public key from private key.
- Error: null.
- Parameters:
signatureOffline(txData, privateKey)
- Parameters:
- txData: data will be signed.
- privateKey: private key will be used to signing txData.
- Returns:
- Success: signature.
- Error: null.
- Parameters:
verifyTransaction(tx)
- Parameters:
- tx: transaction need verifying.
- Returns:
- True: if transaction is valid.
- False: otherwise.
- Parameters:
API
- Properties
- api: uri of api server.
- Constructor
new API(api)
: create new instance API.
- Methods
getBlock(height)
- Parameters:
- height: height of block.
- Returns:
- Success:(Promise) block at height.
- Error: 'Get block failed'.
- Parameters:
getTransaction(txHash)
- Parameters:
- txHash: hash of transaction.
- Returns:
- Success:(Promise) The transaction has transaction hash as input.
- Error: 'Get transaction failed'.
- Parameters:
getAccountDetail(address)
- Parameters:
- address: address of account (hex string, length = 40).
- Returns:
- Success: details of account has address as input.
- Error: 'Get details account failed'.
- Parameters:
getHistoryTransaction({address, page, limit = 10})
- Parameters
- address: address want to get history
- page: number of pages
- limit: default is 10, amount of transactions will be returned in response.
- Returns:
- Success:(Promise) transactions of address.
- Error: 'Get transaction history failed'.
- Parameters
getSequence(address)
- Parameters:
- address: address of account wants to get sequence number.
- Returns:
- Success: (Promise) sequence of address.
- Error:
- 'Get sequence failed'.
- 'Get details account failed'.
- Parameters:
getBalance(address)
- Parameters:
- address: address of account wants to get balance.
- Returns:
- Success: (Promise) balance of address.
- Error:
- 'Get balance failed'.
- 'Get details account failed'.
- Parameters:
getPermission(address)
- Parameters:
- address: address wants to get permission.
- Returns:
- Success: (Promise) permission of address.
- Error:
- 'Get permission failed'.
- 'Get details account failed'.
- Parameters:
getParams(method, body, headers, uri)
: static function- Parameters:
- method: method of request( GET, POST, ...)
- body: body of request
- headers: header of request
- uri: uri of request.
- Returns:
- Success: request as a JSON.
- Parameters:
sendTransaction(tx)
- Parameters:
- tx: transaction will be sent to blockchain network.
- Returns:
- Success: (Promise) transaction hash of transaction.
- Error: 'Send transaction failed'.
- Parameters:
getTransactionFee()
- Returns:
- Success: (Promise) fee and address of receiver.
- Error: 'Get transaction fee failed'.
- Returns:
requestAPI(endpoint, method, body, headers)
- Parameters:
- endpoint: request will be sent to endpoint
- method: method of request (GET, POST)
- body: body of request
- headers: headers of request
- Returns:
- Success: response of request
- Error: 'Error when request data'
- Parameters:
Transaction
- Properties
- webAPI : instance of class API
- wallet : instance of Wallet
- utils : instance of Utils
- CHAINID : chain identify of blockchain.
- Constructor
new Transaction(chainId, urlAPI)
- Parameters:
- chainId: chain id of blockchain
- urlAPI: uri of api server
- Returns: instance of class Transaction
- Parameters:
- Methods
createSendTx(from, to , amount, privateKey)
- Parameters:
- from: address of sender
- to: address of receiver
- amount: amount of token will be sent
- privateKey : private key of sender, which is used to sign transaction.
- Returns:
- Success:(Promise) transaction hash of transaction.
- Other: Error
- Parameters:
Usage
import WalletSDK from 'rn-wallet-sdk-test'
const mnemonic = WalletSDK.Wallet.generateMnemonic()
const wallet = await WalletSDK.Wallet.restoreWallet(mnemonic, password)
const wallet = await WalletSDK.Wallet.generateWallet(mnemonic, password)
const mnemonicEncrypt = WalletSDK.Wallet.encryptString(mnemonic, password)
const mnemonic = WalletSDK.Wallet.decryptString(mnemonicEncrypt, password)
Troubleshooting
Nodejs libraries error
If you continue install some packages on your project, please run rn-nodeify --install --hack
after install them.
@babel/plugin-proposal-throw-expressions
Install this library if your project haven't had it yet to catch throw error
run npm install --dev @babel/plugin-proposal-throw-expressions
or yarn add --dev @babel/plugin-proposal-throw-expressions