Skip to main content

Ronin Injected Provider API

Overview

This is a list of methods provided by the Ronin Wallet's Injected Provider API.

Detecting the provider

Browser extension

When you install the Ronin Wallet browser extension, a window.ronin object is injected:

window.ronin = {
provider
}

The window.ronin.provider is an EIP-1193 provider.

Mobile app

When a web page is displayed in the in-app browser of the Ronin Wallet mobile app, an isWalletApp property is injected:

window.ronin = {
provider
}

window.isWalletApp = true

Method reference

request()

Sends an RPC API request to the wallet and returns a promise that resolves to the result of the RPC method call.

interface RequestArguments {
method: string;
params?: unknown[] | object;
}

window.ronin.provider.request(args: RequestArguments): Promise<unknown>;

The following example shows how to send a sign request to the Ronin Wallet browser extension.

Live Editor
function PersonalSignRequest() {
  async function onClickSign() {
    if(typeof window.ronin === "undefined") {
      alert('Ronin Wallet extension is not installed')
    }
    
    const provider = window.ronin.provider
    const accounts = await provider.request( { method: 'eth_requestAccounts' })
    if(!accounts) {
      return
    }
    const signature = await window.ronin.provider.request({ method: 'personal_sign', params: ['Hello World', accounts[0]]})
    alert(signature)
  }
  
  return (
    <button onClick={onClickSign}>Sign</button>
  )
}
Result
Loading...

sendAsync()

This method is similar to request(), but with JSON-RPC objects and a callback. This is a deprecated API and we suggest using request() instead.

interface JsonRpcRequest {
id: string | undefined
jsonrpc: '2.0'
method: string
params?: Array<any>
}

interface JsonRpcResponse {
id: string | undefined
jsonrpc: '2.0'
method: string
result?: unknown
error?: Error
}

window.ronin.provider.sendAsync(payload: JsonRpcRequest, callback: JsonRpcCallback)

Event reference

The Ronin provider emits events using the Node.js EventEmitter API.

accountsChanged

The provider emits this event when the list of approved accounts changes. This happens when the wallet is locked or when the user edits the session.

The result is equal to the response from eth_requestAccounts or eth_accounts.

window.ronin.provider.on('accountsChanged', (accounts: string) => void)

chainChanged

The provider emits this event when the current selected chain in the wallet changes.

The result is equal to the response from eth_chainId.

window.ronin.provider.on('accountsChanged', (chainId: number) => void)

Error codes

Status codeNameDescription
4001User Rejected RequestThe user rejected the request.
4100UnauthorizedThe requested method and/or account has not been authorized by the user.
4200Unsupported MethodThe provider does not support the requested method.
4900DisconnectedThe provider is disconnected from all chains.
4901Chain DisconnectedThe provider is not connected to the requested chain.