Skip to content

Commit aadf770

Browse files
committed
update
1 parent 172d6cd commit aadf770

14 files changed

+720
-135
lines changed

README.md

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,63 @@
1-
# XRPL JS - Simple JS scripts
1+
# XRPL Scripts - JavaScript & Python 🚀
22

3-
This repository contains JavaScript scripts to interact with the XRP Ledger (XRPL), enabling wallet generation, trustline approval, and transactions.
3+
This repository contains scripts in both JavaScript and Python to interact with the XRP Ledger (XRPL). These scripts allow testing functionalities such as wallet generation, trustline approval, transactions, and Automated Market Maker (AMM) operations.
44

55
## 📁 Project Structure
66

7-
The scripts are located inside the src folder:
7+
The scripts are divided into two main folders:
88

9-
- `generate.js` → Generates a new XRPL wallet (address & seed).
9+
- **`js/`** → Contains JavaScript scripts for XRPL interactions.
10+
- **`python/`** → Contains Python scripts for XRPL interactions.
1011

11-
- `rlusd.js` → Generates a new XRPL wallet (address & seed) and approves a trustline for the RLUSD token on XRPL.
12+
### JavaScript Scripts (`js/`)
13+
- `generate.js` → Generates a new XRPL wallet.
14+
- `trustline.js` → Creates a trustline for RLUSD.
15+
- `xrp_transaction.js` → Handles XRP transactions.
16+
- `amm_create_RLUSD_XRP.js` → Creates an AMM pool for RLUSD/XRP.
17+
- `amm_deposit_RLUSD_XRP.js` → Deposits into an existing AMM pool.
1218

13-
- `transaction.js` → Sends an XRP transaction from one wallet to another.
1419

15-
## 🔧 Installation & Setup
16-
17-
Clone this repo and run `npm i`.
18-
19-
## 📝 Usage
20-
21-
1. Run the following command to generate a new wallet:
22-
23-
`node src/generate.js`
24-
25-
2. Generate a wallet and approve Trustline for RLUSD:
26-
27-
`node src/rlusd.js`
20+
### Python Scripts (`python/`)
21+
- `generate.py` → Generates a new XRPL wallet.
22+
- `trustline.py` → Creates a trustline for RLUSD.
23+
- `xrp_transaction.py` → Handles XRP transactions.
24+
- `amm_create_RLUSD_XRP.py` → Creates an AMM pool for RLUSD/XRP.
25+
- `amm_deposit_RLUSD_XRP.py` → Deposits into an existing AMM pool.
2826

29-
3. Send an XRP Transaction:
30-
31-
Before running this script, update transaction.js with:
32-
- Source Wallet Seed (from generate.js)
33-
- Destination Wallet Address
34-
35-
`node src/transaction.js`
36-
37-
## Links
27+
## 🔧 Installation & Setup
3828

29+
### JavaScript
30+
1. Clone this repo and navigate to the `js/` folder.
31+
2. Run `npm install` to install dependencies.
32+
33+
### Python
34+
1. Navigate to the `python/` folder.
35+
2. Install required packages:
36+
```bash
37+
pip install -r requirements.txt
38+
```
39+
or:
40+
```bash
41+
# Create a virtual env
42+
python3 -m venv myenv
43+
44+
# Activate env
45+
source myenv/bin/activate # On macOS/Linux
46+
# myenv\Scripts\activate # On Windows
47+
48+
# Install xrpl-py in the virtual env
49+
pip install xrpl-py```
50+
```
51+
## ⚠️ Important Notes
52+
- All scripts are designed for the XRPL Testnet.
53+
- Keep your wallet seed secure and never share it.
54+
- Ensure you have sufficient XRP for fees and reserves.
55+
- RLUSD operations require an established trustline first.
56+
57+
## 🔗 Useful Links
3958
- [XRPL Documentation](https://xrpl.org/)
40-
- [More Example](https://docs.xrpl-commons.org/)
59+
- [XRPL Commons Examples](https://docs.xrpl-commons.org/)
4160
- [Ripple Stablecoin](https://ripple.com/solutions/stablecoin/)
61+
- [RLUSD Faucet](https://tryrlusd.com/)
62+
63+

js/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
/myenv
16+
myenv/
17+
18+
# next.js
19+
/.next/
20+
/out/
21+
22+
# production
23+
/build
24+
25+
# misc
26+
.DS_Store
27+
*.pem
28+
29+
# debug
30+
npm-debug.log*
31+
yarn-debug.log*
32+
yarn-error.log*
33+
.pnpm-debug.log*
34+
35+
# env files (can opt-in for committing if needed)
36+
.env*
37+
38+
# vercel
39+
.vercel
40+
41+
# typescript
42+
*.tsbuildinfo
43+
next-env.d.ts

js/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# XRPL JavaScript - Simple JS Scripts 🚀
2+
3+
This repository contains JavaScript scripts to interact with the XRP Ledger (XRPL), enabling wallet generation, trustline creation, transactions, and AMM operations.
4+
5+
## 📁 Project Structure
6+
7+
- `generate.js` → Generates a new XRPL wallet (address & seed) 🔑
8+
- `generate_and_trustline.js` → Generates a wallet and establishes a trustline 🤝
9+
- `trustline.js` → Creates a trustline for the RLUSD token 🔄
10+
- `xrp_transaction.js` → Handles XRP transactions 💸
11+
- `rlusd_transaction.js` → Manages RLUSD token transactions 💰
12+
- `amm_create_RLUSD_XRP.js` → Creates an AMM pool for RLUSD/XRP pair 🏦
13+
- `amm_deposit_RLUSD_XRP.js` → Deposits assets into an existing AMM pool 📥
14+
15+
## 🔧 Installation & Setup
16+
17+
1. Install required packages:
18+
```bash
19+
npm install xrpl
20+
```
21+
22+
## 📝 Usage
23+
24+
1. Generate a new wallet:
25+
```bash
26+
node generate.js
27+
```
28+
29+
2. Generate wallet and create trustline for RLUSD:
30+
```bash
31+
node generate_and_trustline.js
32+
```
33+
34+
3. Create a trustline for an existing wallet:
35+
```bash
36+
node trustline.js
37+
```
38+
*Update the script with your wallet seed first.*
39+
40+
4. Send an XRP transaction:
41+
```bash
42+
node xrp_transaction.js
43+
```
44+
*Update the script with your wallet seed and destination address.*
45+
46+
5. Send an RLUSD transaction:
47+
```bash
48+
node rlusd_transaction.js
49+
```
50+
*Update the script with your wallet seed and destination address.*
51+
52+
6. Create an AMM pool:
53+
```bash
54+
node amm_create_RLUSD_XRP.js
55+
```
56+
*Update the script with your wallet seed and desired initial amounts.*
57+
58+
7. Deposit into an AMM pool:
59+
```bash
60+
node amm_deposit_RLUSD_XRP.js
61+
```
62+
*Update the script with your wallet seed and deposit amounts.*
63+
- [AMM Deposit flags](https://xrpl.org/docs/references/protocol/transactions/types/ammdeposit)
64+
65+
## ⚠️ Important Notes
66+
67+
- All scripts use the XRPL Testnet 🌐
68+
- Keep your seed (private key) **secure** and never share it! 🔒
69+
- Ensure you have sufficient XRP for fees and reserves ⚡
70+
- For RLUSD operations, you need an established trustline first ✅
71+
72+
## 🔗 Useful Links
73+
74+
- [XRPL Documentation](https://xrpl.org/)
75+
- [More Examples](https://docs.xrpl-commons.org/)
76+
- [Ripple Stablecoin](https://ripple.com/solutions/stablecoin/)
77+

js/amm_create_RLUSD_XRP.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const xrpl = require("xrpl");
2+
3+
async function createAmm(seed, tradingFee = 500) {
4+
// Connect to XRPL Testnet 🌐
5+
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233");
6+
await client.connect();
7+
console.log("✅ Connected to XRPL Testnet");
8+
9+
// Generate wallet from seed 🔑
10+
const wallet = xrpl.Wallet.fromSeed(seed);
11+
console.log(`🏦 Wallet Address: ${wallet.address}`);
12+
13+
// Fetch account information 📜
14+
const accountInfo = await client.request({
15+
command: "account_info",
16+
account: wallet.address,
17+
ledger_index: "validated"
18+
});
19+
const sequence = accountInfo.result.account_data.Sequence;
20+
console.log(`🔢 Sequence: ${sequence}`);
21+
22+
// Define the AMM creation transaction 📊
23+
const transaction = {
24+
TransactionType: "AMMCreate",
25+
Account: wallet.address,
26+
Amount: {
27+
currency: "524C555344000000000000000000000000000000", // RLUSD in Hex 💲
28+
issuer: "rQhWct2fv4Vc4KRjRgMrxa8xPN9Zx9iLKV",
29+
value: "1",
30+
},
31+
Amount2: "10000000", // 10 XRP in drops 💰
32+
TradingFee: tradingFee,
33+
Fee: "2000000", // Transaction fee in drops
34+
Flags: 2147483648, // FullyCanonicalSig 🚩
35+
Sequence: sequence,
36+
};
37+
38+
console.log("\n🚀 === Creating AMM ===");
39+
console.log(`📌 Account: ${wallet.address}`);
40+
console.log("💵 RLUSD Amount: 1");
41+
console.log("💎 XRP Amount: 10");
42+
console.log(`📊 Trading Fee: ${tradingFee / 1000}%`);
43+
44+
try {
45+
// Prepare and sign transaction ✍️
46+
const prepared = await client.autofill(transaction);
47+
const signed = wallet.sign(prepared);
48+
49+
// Submit transaction to XRPL 🔄
50+
const response = await client.submitAndWait(signed.tx_blob);
51+
52+
if (response.result.meta.TransactionResult === "tesSUCCESS") {
53+
console.log("\n🎉 AMM created successfully!");
54+
console.log(`🔗 Transaction hash: ${response.result.tx_json.hash}`);
55+
return response;
56+
} else {
57+
console.log("\n❌ AMM creation failed");
58+
console.log(`⚠️ Error: ${response.result.meta.TransactionResult}`);
59+
return response;
60+
}
61+
} catch (error) {
62+
console.error("\n🚨 Error creating AMM:", error);
63+
throw error;
64+
} finally {
65+
// Disconnect from XRPL 🔌
66+
await client.disconnect();
67+
console.log("🔌 Disconnected from XRPL");
68+
}
69+
}
70+
71+
(async () => {
72+
const seed = "sEd71CfChR48xigRKg5AJcarEcgFMPk";
73+
try {
74+
await createAmm(seed, 500);
75+
} catch (error) {
76+
console.error(`🚨 Final error: ${error.message}`);
77+
}
78+
})();

js/amm_deposit_RLUSD_XRP.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const xrpl = require("xrpl");
2+
3+
async function depositRlusd(seed, rlusdAmount = "0.5") {
4+
// Connect to XRPL Testnet 🌐
5+
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233");
6+
await client.connect();
7+
console.log("✅ Connected to XRPL Testnet");
8+
9+
// Generate wallet from seed 🔑
10+
const wallet = xrpl.Wallet.fromSeed(seed);
11+
console.log(`🏦 Wallet Address: ${wallet.address}`);
12+
13+
// Fetch account information 📜
14+
const accountInfo = await client.request({
15+
command: "account_info",
16+
account: wallet.address,
17+
ledger_index: "validated"
18+
});
19+
const sequence = accountInfo.result.account_data.Sequence;
20+
console.log(`🔢 Sequence: ${sequence}`);
21+
22+
// Define RLUSD details 💲
23+
const currencyHex = "524C555344000000000000000000000000000000"; // RLUSD in Hex
24+
const issuer = "rQhWct2fv4Vc4KRjRgMrxa8xPN9Zx9iLKV";
25+
26+
// Define the AMM deposit transaction 📥
27+
const transaction = {
28+
TransactionType: "AMMDeposit",
29+
Account: wallet.address,
30+
Amount: {
31+
currency: currencyHex,
32+
issuer: issuer,
33+
value: rlusdAmount,
34+
},
35+
Asset: {
36+
currency: currencyHex,
37+
issuer: issuer,
38+
},
39+
Asset2: {
40+
currency: "XRP",
41+
},
42+
Flags: 1048576, // tfSingleAsset 🚩 or tfTwoAsset if you want to deposit XRP to: 2097152
43+
Fee: "10",
44+
Sequence: sequence,
45+
};
46+
47+
console.log("\n💰 === Depositing RLUSD to AMM ===");
48+
console.log(`📌 Account: ${wallet.address}`);
49+
console.log(`💵 RLUSD Amount: ${rlusdAmount} RLUSD`);
50+
51+
try {
52+
// Prepare and sign transaction ✍️
53+
const prepared = await client.autofill(transaction);
54+
const signed = wallet.sign(prepared);
55+
console.log("🔏 Transaction signed");
56+
// Submit transaction to XRPL 🔄
57+
const response = await client.submitAndWait(signed.tx_blob);
58+
59+
if (response.result.meta.TransactionResult === "tesSUCCESS") {
60+
console.log("\n🎉 Deposit successful!");
61+
console.log(`🔗 Transaction hash: ${response.result.tx_json.hash}`);
62+
return response;
63+
} else {
64+
console.log("\n❌ Deposit failed");
65+
console.log(`⚠️ Error: ${response.result.meta.TransactionResult}`);
66+
return response;
67+
}
68+
} catch (error) {
69+
console.error("\n🚨 Error making deposit:", error);
70+
throw error;
71+
} finally {
72+
// Disconnect from XRPL 🔌
73+
await client.disconnect();
74+
console.log("🔌 Disconnected from XRPL");
75+
}
76+
}
77+
78+
(async () => {
79+
const seed = "sEd71CfChR48xigRKg5AJcarEcgFMPk";
80+
const rlusdAmount = "0.5";
81+
try {
82+
await depositRlusd(seed, rlusdAmount);
83+
} catch (error) {
84+
console.error(`🚨 Final error: ${error.message}`);
85+
}
86+
})();

0 commit comments

Comments
 (0)