Created
January 28, 2023 02:08
-
-
Save dvwright/697b1ee0e130d433cad5c6e1f43fa2fb to your computer and use it in GitHub Desktop.
XRPL Create Trustline Node JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* XRP | |
* https://xrpl.org/xrp-testnet-faucet.html | |
* https://xrpl.org/tx-sender.html | |
* | |
* Your Testnet Credentials: | |
* | |
* Address | |
* r************ | |
* | |
* Secret | |
* s************** | |
*/ | |
const xrpl = require("xrpl"); | |
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233"); | |
setTrustline(); | |
async function setTrustline() { | |
await client.connect(); | |
const your_wallet = "r*******"; | |
const operational_wallet = xrpl.Wallet.fromSeed( | |
"s***********" | |
); | |
const stably_testnet_usds = "r3QrC1z78cynREz4zvJ7UFg8k1goRf4PZV"; | |
console.log("Balances of wallets before Payment tx"); | |
console.log(await client.getXrpBalance(your_wallet)); | |
const trustSet_tx = { | |
TransactionType: "TrustSet", | |
Account: your_wallet, | |
LimitAmount: { | |
currency: "USD", | |
issuer: stably_testnet_usds, | |
value: xrpl.xrpToDrops("1000"), | |
}, | |
}; | |
const ts_prepared = await client.autofill(trustSet_tx); | |
const ts_signed = operational_wallet.sign(ts_prepared); | |
const ts_result = await client.submitAndWait(ts_signed.tx_blob); | |
let results = ""; | |
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") { | |
results = | |
"\nTrustline established between account \n" + | |
operational_wallet.address + | |
" \n and account\n" + | |
stably_testnet_usds + | |
"."; | |
} else { | |
results = "\nTrustLine failed. See JavaScript console for details."; | |
throw "Error sending transaction: ${ts_result.result.meta.TransactionResult}"; | |
} | |
console.log("Results", results); | |
await client.disconnect(); | |
} | |
// to run: node xpr_create_trustline_testnet.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment