Skip to main content

Ronin Injected Provider API

Overview

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

Ways to detect an injected 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 Webview

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

window.ronin = {
provider
}

window.isWalletApp = true

Methods

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 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)

Events

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 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)

Errors

The following is a list of provider errors.

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.
Was this helpful?
Happy React is loading...