Files
xrpl-dev-portal/docs/tutorials/how-tos/testing-devnet-features.md
2024-10-09 15:26:34 -07:00

6.3 KiB

html, parent, seo, labels
html parent seo labels
testing-devnet-features.html how-tos.html
description
Guide on using pre-release transaction types on the XRP Ledger for developers.
Development
Customization
Devnet

Test Pre-Release Transaction Types

(Requires cloning and modifying XRPL core repositories and understanding of XRPL transaction serialization).

Pre-release transactions are amendments that represent new features or other changes to transaction processing. Features are typically released to the XRPL Devnet for early testing.

This guide walks through the steps to test transaction types in development using either JavaScript with xrpl.js or Python with xrpl-py. This approach is typically only necessary for pre-release amendments that are available on the XRPL Devnet for early testing.

Note: The code samples below illustrate how to prepare your development environment and modify the XRPL to support custom transaction types, using the respective client library.

Prerequisites

  • Basic understanding of XRPL transactions.
  • Development environment setup for JavaScript or Python.
  • Docker installed and configured.

Steps

1. Set Up Your Development Environment

Ensure the proper dependencies are installed for Node.js or Python.

{% tabs %}

{% tab label="JavaScript" %}

npm install xrpl

{% /tab %}

{% tab label="Python" %}

pip install xrpl-py

{% /tab %}

{% /tabs %}

2. Generate Definitions File

Utilize the server_definitions command to retrieve the definitions.json content.

{% admonition type="info" name="Note" %}Any parallel test network may be used instead of Devnet.{% /admonition %}

{% tabs %}

{% tab label="Linux" %}

curl -X POST https://s.devnet.rippletest.net:51234/ -H 'Content-Type: application/json' -d '{"method": "server_definitions"}' > definitions.json

{% /tab %}

{% tab label="Mac" %}

curl -X POST https://s.devnet.rippletest.net:51234/ -H 'Content-Type: application/json' -d '{"method": "server_definitions"}' > definitions.json

{% /tab %}

{% tab label="Windows (Cmd)" %}

curl -X POST https://s.devnet.rippletest.net:51234/ -H "Content-Type: application/json" -d "{\"method\": \"server_definitions\"}" > definitions.json

{% /tab %}

{% tab label="Windows (PowerShell)" %}

curl -Method Post -Uri https://s.devnet.rippletest.net:51234/ -Headers @{"Content-Type"="application/json"} -Body '{"method": "server_definitions"}' | Out-File -FilePath definitions.json

{% /tab %}

{% /tabs %}

3. Update XRPL Library Definitions

Copy the generated definitions.json to your XRPL library installation.

{% tabs %}

{% tab label="JavaScript" %}

// Locate your ripple-binary-codec installation in node_modules and replace the definitions.json file.
// <_your project directory_>/node_modules/ripple-binary-codec/dist/definitions.json

{% /tab %}

{% tab label="Python" %}

// Use `pip show xrpl-py` to find the installation location and navigate to `<_output of pip show_>/xrpl/core/binarycodec/definitions/definitions.json` to replace the `definitions.json` file.

{% /tab %}

{% /tabs %}

4. Create and Submit Custom Transaction

{% tabs %}

{% tab label="JavaScript" %}

const { Client, Wallet } = require('xrpl');
const { encode } = require('ripple-binary-codec');

async function main() {
  const client = new Client("wss://s.devnet.rippletest.net:51233");
  await client.connect();

  const wallet = Wallet.fromSeed('sYOURSEEDHERE');

  const customTx = {
    TransactionType: 'NewTransactionType',
    Account: wallet.address,
    // additional fields for the new transaction
  };

  // If using Typescript, you will need to encode to allow typechecks to function
  // or just us @ts-expect-error when calling submit
  //   const encodedTransaction = encode(customTx);

  await client.submitAndWait(customTx, { wallet });
  // If using typescript, you should pass the encoded string of the transaction or us @ts-expect-error
  //   await client.submitAndWait(encodedTransaction, { wallet });
  // await client.disconnect();
}

main();
// Or call await main(); if your nodejs versions supports top level await

{% /tab %}

{% tab label="Python" %}

from xrpl.clients import JsonRpcClient
from xrpl.models.transactions import Transaction
from xrpl.wallet import Wallet
from xrpl.transaction import send_reliable_submission
from xrpl.core.binarycodec import encode

client = JsonRpcClient("wss://s.devnet.rippletest.net:51233")

wallet = Wallet(seed="sYOURSEEDHERE", sequence=0)

custom_tx = Transaction(
    account=wallet.classic_address,
    transaction_type="NewTransactionType",
    # additional fields for the new transaction
)

# If using typechecking, encode the transaction into a string before passing to send_reliable_submission
# because the new transaction type is not natively supported by xrpl-py and therefore will have a type
# error if you pass an unsupported transaction type
# encoded_tx = encode(custom_tx)

send_reliable_submission(custom_tx, client, wallet)
# If using typechecking, encode the transaction into a string before passing to send_reliable_submission
# because the new transaction type is not natively supported by xrpl-py and therefore will have a type
# error if you pass an unsupported transaction type
# send_reliable_submission(encoded_tx, client, wallet)
# Or disable type checking for the line
# send_reliable_submission(custom_tx, client, wallet) # type: ignore

{% /tab %}

{% /tabs %}

Considerations

  • Testing: Utilize the XRPL Testnet or Devnet for testing new transaction types.
  • Updates: Regularly update your rippled and XRPL library clones to include the latest features and fixes.
  • Custom Types and Serialization: If your transaction involves new data structures, ensure they are correctly defined and serialized according to XRPL standards.

{% raw-partial file="/docs/_snippets/common-links.md" /%}