API Reference

This section provides a comprehensive guide on how to use the XRPL Snap API. It covers installation, interaction with the XRPL Snap, network management, and handling transactions, including exporting the private key.


Installation

To install the XRP Ledger Snap in your MetaMask environment, use the following request:

provider.request({
  method: 'wallet_requestSnaps',
  params: {
    ['npm:xrpl-snap']: {},
  },
});

For Development: If you are developing the XRP Ledger Snap locally, use this request to install it from your local environment:

provider.request({
  method: 'wallet_requestSnaps',
  params: {
    ['local:http://localhost:8080']: {},
  },
});

This is only for developer looking to contribute to the Snap


Interact with the Snap

Once the XRP Ledger Snap is installed, you can interact with it using the following methods:

Making RPC Requests

You can interact with the XRP Ledger via the Snap by sending RPC requests. Here is an example:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_request',
      params: { 
        command: 'account_info', 
        account: 'rBg...' // Add your account here
      },
    },
  },
});

This example requests account information from the XRP Ledger.


Network Management

Get Supported Networks

To retrieve a list of networks supported by the XRPL Snap:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_getSupportedNetworks',
    },
  },
});

Get Current Network

To check the currently active network:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_getActiveNetwork',
    },
  },
});

Change the Selected Network

To switch to a different network:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_changeNetwork',
      params: { 
        chainId: 1  // Replace with the correct chainId for the desired network
      },
    },
  },
});

Signing and Submitting Transactions

The XRP Ledger Snap allows you to sign and submit transactions directly from your DApp.

Sign and Submit a Transaction

To sign and submit a transaction to the XRP Ledger:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'Payment',
        Account: 'rBg...',     // Your account address
        Destination: 'rPT...', // Destination address
        Amount: '1000000',     // Amount in drops (1 XRP = 1,000,000 drops)
      },
    },
  },
});

Sign a Transaction Without Submitting

If you only need to sign a transaction without submitting it to the network:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:@peersyst/xrpl-snap',
    request: {
      method: 'npm:xrpl-snap',
      params: {
        TransactionType: 'Payment',
        Account: 'rBg...',
        Destination: 'rPT...',
        Amount: '1000000', // Amount in drops
      },
    },
  },
});

Normally you will use the xrpl_signAndSubmit method.


Export Private Key

To display the user's private key in the XRP Ledger Snap use this method.

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_extractPrivateKey',
      params: undefined,
    },
  },
})

The private key never leaves the MetaMask environment, therefore you as a developer can not access to it.


Last updated