Class ApiBase<ApplyResult>

    • Field Detail

      • signer

        public Types.Signer signer
        An external signer which will be used to sign extrinsic when account passed in is not KeyringPair
      • rpcRx

        public RpcRx rpcRx
      • genesisHash

        public Hash genesisHash
        Contains the genesis Hash of the attached chain. Apart from being useful to determine the actual chain, it can also be used to sign immortal transactions.
      • runtimeVersion

        public RuntimeVersion runtimeVersion
        Contains the version information for the current runtime.
    • Constructor Detail

      • ApiBase

        public ApiBase​(IProvider provider,
                       ApiBase.ApiType apiType)
        Create an instance of the class
        Parameters:
        provider - the Provider instance
        apiType - the type of the API

        **Example** ```java import org.polkadot.api.ApiBase; ApiBase api = new ApiBase(); api.rpc().subscribeNewHead((header) => { System.out.println("new block "); System.out.println(header.blockNumber); }); ```

    • Method Detail

      • derive

        public Types.Derive<ApplyResult> derive()
        Derived results that are injected into the API, allowing for combinations of various query results.

        **Example** ```java api.derive.chain.bestNumber((number) => { System.out.print("best number "); System.out.println(number); }); ```

        Specified by:
        derive in interface IApi<ApplyResult>
      • query

        public Types.QueryableStorage<ApplyResult> query()
        Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.

        All calls inside the namespace, is denoted by `section`.`method` and may take an optional query parameter. As an example, `api.query.timestamp.now()` (current block timestamp) does not take parameters, while `api.query.system.accountNonce()` (retrieving the associated nonce for an account), takes the `AccountId` as a parameter.

        **Example**

        ```java api.query.balances.freeBalance(, (balance) => { System.out.print("new balance "); System.out.println(balance); }); ```

        Specified by:
        query in interface IApi<ApplyResult>
      • rpc

        public Types.DecoratedRpc<ApplyResult> rpc()
        Contains all the raw rpc sections and their subsequent methods in the API as defined by the jsonrpc interface definitions. Unlike the dynamic `api.query` and `api.tx` sections, these methods are fixed (although extensible with node upgrades) and not determined by the runtime.

        RPC endpoints available here allow for the query of chain, node and system information, in addition to providing interfaces for the raw queries of state (usine known keys) and the submission of transactions.

        **Example** ```java api.rpc.chain.subscribeNewHead((header) => { System.out.print("new header "); System.out.println(header); }); ```

        Specified by:
        rpc in interface IApi<ApplyResult>
      • tx

        public Types.SubmittableExtrinsics tx()
        Contains all the extrinsic modules and their subsequent methods in the API. It allows for the construction of transactions and the submission thereof. These are attached dynamically from the runtime metadata.

        **Example** ```java api.tx.balances .transfer(, ) .signAndSend(, ({status}) => { System.out.print("tx status "); System.out.println(status.asFinalized.toHex()); }); ```

        Specified by:
        tx in interface IApi<ApplyResult>
      • on

        public EventEmitter on​(IProvider.ProviderInterfaceEmitted type,
                               EventEmitter.EventListener handler)
        Attach an eventemitter handler to listen to a specific event
        Specified by:
        on in interface Types.ApiBaseInterface<ApplyResult>
        Parameters:
        type - The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`
        handler - The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments. **Example**

        ```java api.on('connected', () => { System.out.println("API has been connected to the endpoint"); }); api.on('disconnected', () => { System.out.println("API has been disconnected from the endpoint"); }); ```

      • once

        public EventEmitter once​(IProvider.ProviderInterfaceEmitted type,
                                 EventEmitter.EventListener handler)
        Attach an one-time eventemitter handler to listen to a specific event
        Specified by:
        once in interface Types.ApiBaseInterface<ApplyResult>
        Parameters:
        type - The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`
        handler - The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments. **Example** ```java api.once('connected', () => { System.out.println("API has been connected to the endpoint"); }); api.once('disconnected', () => { System.out.println("API has been disconnected from the endpoint"); }); ```
      • getGenesisHash

        public Hash getGenesisHash()
        Contains the genesis Hash of the attached chain. Apart from being useful to determine the actual chain, it can also be used to sign immortal transactions.
        Specified by:
        getGenesisHash in interface IApi<ApplyResult>
      • hasSubscriptions

        public boolean hasSubscriptions()
        `true` when subscriptions are supported
      • runtimeMetadata

        public Metadata runtimeMetadata()
        Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.
      • setSigner

        public void setSigner​(Types.Signer signer)
        Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
      • disconnect

        public void disconnect()
        Disconnect from the underlying provider, halting all comms