Nourishing Pear Medley

    @elrondnetwork/erdrxjs
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.2 • Public • Published

    @elrondnetwork/erdrxjs

    Rxjs wrapper over the erdjs npm package.

    Installation

    npm i @elrondnetwork/erdrxjs

    Dependencies

    Usage

    The package exposes an initialization function (called init) which returns an object of type RxElrond that contains all the implemented functionalities.

    These functionalities are:

    account.get: (input: GetAccountInput) => Observable<Account>

    Returns a synchronised Account object based on an account address or mnemonic

    account.generateMnemonic: () => Observable<Mnemonic>

    Generates a new account mnemonic

    transaction.build: (input: TransactionInput) => Observable<Transaction>

    Builds and signs a new Transaction based on the given input

    transaction.send: (transaction: Transaction) => Observable<SendResponse>

    Sends an already signed transaction

    transaction.status: (txHash: string) => Observable<TransactionStatus>

    Gets the network status of an already sent transaction

    The signature of the init function is the following:

    init: (network: Network<Gateway>): RxElrond

    Exposed types

    TransactionInput

    Input type used by the transaction.build function. Its declaration is the following:

    type TransactionInput = {
        mnemonic: string,
        receiver: string,
        value: number,
        nonce: number,
        data?: any
    }

    SendResponse

    Result type returned by the transaction.send function. Its declaration is the following:

    type SendResponse = {
        hash: string,
        transaction: Transaction
    }

    GetAccountInput

    Input type used by the account.get function. Its declaration is the following:

    type Input = {
        type: 'address' | 'mnemonic',
        value: string
    }

    Gateway

    Enum type representing the gateway url. Its declaration is the following:

    enum Gateway {
        TestNet = 'https://testnet-gateway.elrond.com',
        DevNet = 'https://devnet-gateway.elrond.com',
        MainNet = 'https://gateway.elrond.com'
    }

    Network

    Input type used by the init function to set network parameters. Its declaration is the following:

    type Network<GatewayType extends Gateway> = {
        gateway: GatewayType
    }

    Example

    import {mergeMap, tap} from 'rxjs/operators'
    import {init, Gateway} from '@elrondnetwork/erdrxjs'
    
    const {account, transaction} = init({gateway: Gateway.TestNet})
    
    // Get an account object and print it
    account.get({type: 'address', value: 'exampleAddress'})
        .pipe(tap(account => console.log(account)))
        .subscribe()
    
    account.get({type: 'mnemonic', value: 'exampleMnemonic'})
        .pipe(tap(account => console.log(account)))
        .subscribe()
    
    // Generate an account mnemonic and print it
    account.generateMnemonic()
        .pipe(tap(mnemonic => console.log(mnemonic)))
        .subscribe()
    
    // Build and send a transaction
    const input = {
        mnemonic: 'exampleMnemonic',
        receiver: 'exampleAddress2',
        value: 0,
        nonce: 16,
        data: 'exampleData'
    }
    
    transaction.build(input)
        .pipe(mergeMap(transaction.send))
        .pipe(tap(response => console.log('Tx hash is ', response.hash)))
        .subscribe()
    
    // Get a transaction's status
    
    const txHash = 'exampleTransactionHash'
    
    transaction.status(txHash)
        .pipe(tap(status => console.log(status)))
        .subscribe()

    Keywords

    none

    Install

    npm i @elrondnetwork/erdrxjs

    DownloadsWeekly Downloads

    6

    Version

    0.0.2

    License

    none

    Unpacked Size

    27.6 kB

    Total Files

    77

    Last publish

    Collaborators

    • cipriand
    • stanislav
    • tanghel
    • lucian.mincu
    • ccorcoveanu
    • titel
    • valentinlup
    • arhtudormorar
    • andreibancioiu