xrpl.js 2.0: clean up issue a token examples

This commit is contained in:
mDuo13
2021-10-20 11:39:43 -07:00
parent 92a8faecac
commit ee927ebf94
4 changed files with 29 additions and 783 deletions

View File

@@ -10,14 +10,14 @@ if (typeof module !== "undefined") {
// Connect ---------------------------------------------------------------------
async function main() {
api = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
console.log("Connecting to Testnet...")
await api.connect()
await client.connect()
// Get credentials from the Testnet Faucet -----------------------------------
console.log("Requesting addresses from the Testnet faucet...")
const hot_wallet = (await api.fundWallet()).wallet
const cold_wallet = (await api.fundWallet()).wallet
const hot_wallet = (await client.fundWallet()).wallet
const cold_wallet = (await client.fundWallet()).wallet
console.log(`Got hot address ${hot_wallet.address} and cold address ${cold_wallet.address}.`)
// Configure issuer (cold address) settings ----------------------------------
@@ -27,15 +27,16 @@ async function main() {
"TransferRate": 0,
"TickSize": 5,
"Domain": "6578616D706C652E636F6D", // "example.com"
"SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
//"Flags": (xrpl.AccountSetTfFlags.tfDisallowXRP |
// xrpl.AccountSetTfFlags.tfRequireDestTag)
"SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple,
// Using tf flags, we can enable more flags in one transaction
"Flags": (xrpl.AccountSetTfFlags.tfDisallowXRP |
xrpl.AccountSetTfFlags.tfRequireDestTag)
}
const cst_prepared = await api.autofill(cold_settings_tx)
const cst_prepared = await client.autofill(cold_settings_tx)
const cst_signed = cold_wallet.sign(cst_prepared)
console.log("Sending cold address AccountSet transaction...")
const cst_result = await api.submitAndWait(cst_signed.tx_blob)
const cst_result = await client.submitAndWait(cst_signed.tx_blob)
if (cst_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${cst_signed.hash}`)
} else {
@@ -49,16 +50,17 @@ async function main() {
"TransactionType": "AccountSet",
"Account": hot_wallet.address,
"Domain": "6578616D706C652E636F6D", // "example.com"
"SetFlag": 2 // enable Require Auth so we can't use trust lines that users
// make to the hot address, even by accident.
//"Flags": (api.AccountSetAsfFlags.asfDisallowXRP |
// api.AccountSetAsfFlags.asfRequireDestTag)
// enable Require Auth so we can't use trust lines that users
// make to the hot address, even by accident:
"SetFlag": xrpl.AccountSetAsfFlags.asfRequireAuth,
"Flags": (xrpl.AccountSetTfFlags.tfDisallowXRP |
xrpl.AccountSetTfFlags.tfRequireDestTag)
}
const hst_prepared = await api.autofill(hot_settings_tx)
const hst_prepared = await client.autofill(hot_settings_tx)
const hst_signed = hot_wallet.sign(hst_prepared)
console.log("Sending hot address AccountSet transaction...")
const hst_result = await api.submitAndWait(hst_signed.tx_blob)
const hst_result = await client.submitAndWait(hst_signed.tx_blob)
if (hst_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${hst_signed.hash}`)
} else {
@@ -78,10 +80,10 @@ async function main() {
}
}
const ts_prepared = await api.autofill(trust_set_tx)
const ts_prepared = await client.autofill(trust_set_tx)
const ts_signed = hot_wallet.sign(ts_prepared)
console.log("Creating trust line from hot address to issuer...")
const ts_result = await api.submitAndWait(ts_signed.tx_blob)
const ts_result = await client.submitAndWait(ts_signed.tx_blob)
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${ts_signed.hash}`)
} else {
@@ -99,13 +101,15 @@ async function main() {
"value": issue_quantity,
"issuer": cold_wallet.address
},
"Destination": hot_wallet.address
"Destination": hot_wallet.address,
"DestinationTag": 1 // Needed since we enabled Require Destination Tags
// on the hot account earlier.
}
const pay_prepared = await api.autofill(send_token_tx)
const pay_prepared = await client.autofill(send_token_tx)
const pay_signed = cold_wallet.sign(pay_prepared)
console.log(`Sending ${issue_quantity} ${currency_code} to ${hot_wallet.address}...`)
const pay_result = await api.submitAndWait(pay_signed.tx_blob)
const pay_result = await client.submitAndWait(pay_signed.tx_blob)
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}`)
} else {
@@ -114,7 +118,7 @@ async function main() {
// Check balances ------------------------------------------------------------
console.log("Getting hot address balances...")
const hot_balances = await api.request({
const hot_balances = await client.request({
command: "account_lines",
account: hot_wallet.address,
ledger_index: "validated"
@@ -122,7 +126,7 @@ async function main() {
console.log(hot_balances.result)
console.log("Getting cold address balances...")
const cold_balances = await api.request({
const cold_balances = await client.request({
command: "gateway_balances",
account: cold_wallet.address,
ledger_index: "validated",
@@ -130,7 +134,7 @@ async function main() {
})
console.log(JSON.stringify(cold_balances.result, null, 2))
api.disconnect()
client.disconnect()
} // End of main()
main()