mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-19 03:05:49 +00:00
Revise payment tutorials, add/remove screenshots
This commit is contained in:
158
_code-samples/modular-tutorials/account-support.js
Normal file
158
_code-samples/modular-tutorials/account-support.js
Normal file
@@ -0,0 +1,158 @@
|
||||
// ******************************************************
|
||||
// ************* Get the Preferred Network **************
|
||||
// ******************************************************
|
||||
|
||||
function getNet() {
|
||||
let net
|
||||
if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233/"
|
||||
if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233/"
|
||||
const client = new xrpl.Client(net)
|
||||
return net
|
||||
} // End of getNet()
|
||||
|
||||
// *******************************************************
|
||||
// ************* Get Account *****************************
|
||||
// *******************************************************
|
||||
|
||||
async function getAccount() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.`
|
||||
let faucetHost = null
|
||||
const my_wallet = (await client.fundWallet(null, { faucetHost})).wallet
|
||||
const newAccount = [my_wallet.address, my_wallet.seed]
|
||||
return (newAccount)
|
||||
client.disconnect()
|
||||
} // End of getAccount()
|
||||
|
||||
async function getNewAccount1() {
|
||||
account1address.value = "Getting new account."
|
||||
const accountInfo= await getAccount()
|
||||
account1address.value = accountInfo[0]
|
||||
account1seed.value = accountInfo[1]
|
||||
}
|
||||
|
||||
async function getNewAccount2() {
|
||||
account2address.value = "Getting new account."
|
||||
const accountInfo= await getAccount()
|
||||
account2address.value = accountInfo[0]
|
||||
account2seed.value = accountInfo[1]
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// ********** Get Account from Seed ********************
|
||||
// *****************************************************
|
||||
|
||||
async function getAccountFromSeed(my_seed) {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = '\nConnected, finding wallet.\n'
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(my_seed)
|
||||
// ----------------------Populate the fields for left and right accounts.
|
||||
const address = wallet.address
|
||||
client.disconnect()
|
||||
return (address)
|
||||
} // End of getAccountFromSeed()
|
||||
|
||||
// *****************************************************
|
||||
// ********** Get Account from Seed1 *******************
|
||||
// *****************************************************
|
||||
|
||||
async function getAccountFromSeed1() {
|
||||
account1address.value = await getAccountFromSeed(account1seed.value)
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// ********** Get Account from Seed2 *******************
|
||||
// *****************************************************
|
||||
|
||||
async function getAccountFromSeed2() {
|
||||
account2address.value = await getAccountFromSeed(account2seed.value)
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// ************ Gather Account Info ********************
|
||||
// *****************************************************
|
||||
|
||||
function gatherAccountInfo() {
|
||||
let accountData = account1name.value + "\n" + account1address.value + "\n" + account1seed.value + "\n"
|
||||
accountData += account2name.value + "\n" + account2address.value + "\n" + account2seed.value
|
||||
resultField.value = accountData
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// ********** Distribute Account Info ******************
|
||||
// *****************************************************
|
||||
|
||||
function distributeAccountInfo() {
|
||||
let accountInfo = resultField.value.split("\n")
|
||||
account1name.value = accountInfo[0]
|
||||
account1address.value = accountInfo[1]
|
||||
account1seed.value = accountInfo[2]
|
||||
account2name.value = accountInfo[3]
|
||||
account2address.value = accountInfo[4]
|
||||
account2seed.value = accountInfo[5]
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// ************ Populate Active Form 1 *****************
|
||||
// *****************************************************
|
||||
|
||||
function populate1() {
|
||||
accountNameField.value = account1name.value
|
||||
accountAddressField.value = account1address.value
|
||||
accountSeedField.value = account1seed.value
|
||||
getXrpBalance()
|
||||
}
|
||||
|
||||
// *****************************************************
|
||||
// ************ Populate Active Form 2 *****************
|
||||
// *****************************************************
|
||||
|
||||
function populate2() {
|
||||
accountNameField.value = account2name.value
|
||||
accountAddressField.value = account2address.value
|
||||
accountSeedField.value = account2seed.value
|
||||
getXrpBalance()
|
||||
}
|
||||
|
||||
// *******************************************************
|
||||
// **************** Get Xrp Balance *********************
|
||||
// *******************************************************
|
||||
|
||||
async function getXrpBalance() {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
xrpBalanceField.value = await client.getXrpBalance(accountAddressField.value)
|
||||
client.disconnect()
|
||||
} // End of getXrpBalance()
|
||||
|
||||
// *******************************************************
|
||||
// ************** Get Token Balance *********************
|
||||
// *******************************************************
|
||||
|
||||
async function getTokenBalance() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
resultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results= "\nGetting account balance...\n"
|
||||
const balance = await client.request({
|
||||
command: "gateway_balances",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated",
|
||||
})
|
||||
results += JSON.stringify(balance.result, null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // End of getTokenBalance()
|
||||
|
||||
201
_code-samples/modular-tutorials/base-module.html
Normal file
201
_code-samples/modular-tutorials/base-module.html
Normal file
@@ -0,0 +1,201 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>XRPL Base Module</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src='send-xrp.js'></script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>XRPL Base Module</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="sendXRP()">Send XRP</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Amount of XRP to send.">
|
||||
<label for="amountField">Amount</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="amountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getXrpBalance()">Get XRP Balance</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Destination account address where XRP is sent.">
|
||||
<lable for="destinationField">Destination</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="destinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getTokenBalance()">Get Token Balance</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
280
_code-samples/modular-tutorials/create-conditional-escrow.html
Normal file
280
_code-samples/modular-tutorials/create-conditional-escrow.html
Normal file
@@ -0,0 +1,280 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Create a Conditional Escrow</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src="create-time-escrow.js"></script>
|
||||
<script src='create-conditional-escrow.js'></script>
|
||||
<script>
|
||||
if (typeof module !== "undefined") {
|
||||
const xrpl = require('xrpl')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Create a Conditional Escrow</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Amount of XRP to send.">
|
||||
<label for="amountField">Amount</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="amountField" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Destination account address where the escrow is sent.">
|
||||
<lable for="destinationField">Destination</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="destinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="createConditionalEscrow()">Create Escrow</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Condition code used to begin the escrow transaction.">
|
||||
<lable for="escrowConditionField">Escrow Condition</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowConditionField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getEscrows()">Get Escrows</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Fullfillment code to complete the escrow transaction.">
|
||||
<lable for="escrowFulfillmentField">Escrow Fulfillment</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowFulfillmentField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="finishConditionalEscrow()">Finish Escrow</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow cancel time, in seconds.">
|
||||
<lable for="escrowCancelDateField">Escrow Cancel Time</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowCancelDateField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="cancelEscrow()">Cancel Escrow</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow sequence number, used when finishing the escrow.">
|
||||
<lable for="escrowSequenceNumberField">Escrow Sequence Number</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowSequenceNumberField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getTransaction()">Get Transaction</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow owner, the account that created the escrow.">
|
||||
<lable for="escrowOwnerField">Escrow Owner</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowOwnerField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Transaction number, used with the Get Transaction button.">
|
||||
<lable for="transactionField">Transaction</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="transactionField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
84
_code-samples/modular-tutorials/create-conditional-escrow.js
Normal file
84
_code-samples/modular-tutorials/create-conditional-escrow.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// *******************************************************
|
||||
// ************* Create Conditional Escrow ***************
|
||||
// *******************************************************
|
||||
|
||||
async function createConditionalEscrow() {
|
||||
|
||||
//------------------------------------------------------Connect to the Ledger
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}, creating conditional escrow.\n`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
|
||||
wallet.address
|
||||
|
||||
let escrow_cancel_date = new Date()
|
||||
escrow_cancel_date = addSeconds(parseInt(escrowCancelDateField.value))
|
||||
|
||||
// ------------------------------------------------------- Prepare transaction
|
||||
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"CancelAfter": escrow_cancel_date,
|
||||
"Condition": escrowConditionField.value
|
||||
})
|
||||
|
||||
// ------------------------------------------------ Sign prepared instructions
|
||||
const signed = wallet.sign(escrowTx)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nSequence Number (Save!): " + tx.result.tx_json.Sequence
|
||||
results += "\n\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
|
||||
// ----------------------------------------------Disconnect from the XRP Ledger
|
||||
client.disconnect()
|
||||
|
||||
} // End of createTimeEscrow()
|
||||
|
||||
// *******************************************************
|
||||
// ************** Finish Conditional Escrow **************
|
||||
// *******************************************************
|
||||
|
||||
async function finishConditionalEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}, fulfilling conditional escrow.\n`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
|
||||
// ------------------------------------------------------- Prepare transaction
|
||||
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value),
|
||||
"Condition": escrowConditionField.value,
|
||||
"Fulfillment": escrowFulfillmentField.value
|
||||
})
|
||||
|
||||
// ------------------------------------------------ Sign prepared instructions
|
||||
const signed = wallet.sign(prepared)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
|
||||
} // End of finishEscrow()
|
||||
249
_code-samples/modular-tutorials/create-offer.html
Normal file
249
_code-samples/modular-tutorials/create-offer.html
Normal file
@@ -0,0 +1,249 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Create Offers</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src='send-xrp.js'></script>
|
||||
<script src='create-offer.js'></script>
|
||||
<script>
|
||||
if (typeof module !== "undefined") {
|
||||
const xrpl = require('xrpl')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Create Offers</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<h4 align="center">Taker Pays</h4>
|
||||
</td>
|
||||
<td>
|
||||
<h4 align="center">Taker Gets</h4>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Currency codes for the Pay and Get offers.">
|
||||
<lable for="payCurrencyField">Currency Code</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="payCurrencyField" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="getCurrencyField" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="createOffer()">Create Offer</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Issuers of the offered currencies.">
|
||||
<lable for="payIssuerField">Issuer</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="payIssuerField" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="getIssuerField" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getOffers()">Get Offers</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Amounts of offered currencies.">
|
||||
<lable for="amountField">Amount</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="payAmountField" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="getAmountField" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="cancelOffer()">Cancel Offer</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Sequence number of the offer.">
|
||||
<lable for="offerSequenceField">Offer Sequence</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="offerSequenceField" size="40"></input>
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<button type="button" onClick="getTokenBalance()">Get Token Balance</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
125
_code-samples/modular-tutorials/create-offer.js
Normal file
125
_code-samples/modular-tutorials/create-offer.js
Normal file
@@ -0,0 +1,125 @@
|
||||
/***********************************
|
||||
*********** Create Offer **********
|
||||
**********************************/
|
||||
|
||||
async function createOffer() {
|
||||
let net = getNet()
|
||||
let results = 'Connecting to ' + net + '....\n'
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
|
||||
results += "Connected. Getting wallets.\n"
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += accountNameField.value + " account address: " + wallet.address + "\n"
|
||||
resultField.value = results
|
||||
|
||||
|
||||
if (getCurrencyField.value == 'XRP') {
|
||||
takerGets = getAmountField.value
|
||||
} else {
|
||||
takerGetsString = '{"currency": "' + getCurrencyField.value +'",\n' +
|
||||
'"issuer": "' + getIssuerField.value + '",\n' +
|
||||
'"value": "' + getAmountField.value + '"}'
|
||||
takerGets = JSON.parse(takerGetsString)
|
||||
}
|
||||
|
||||
if (payCurrencyField.value == 'XRP') {
|
||||
takerPays = payAmountField.value
|
||||
} else {
|
||||
takerPaysString = '{"currency": "' + payCurrencyField.value + '",\n' +
|
||||
'"issuer": "' + payIssuerField.value + '",\n' +
|
||||
'"value": "' + payAmountField.value + '"}'
|
||||
takerPays = JSON.parse(takerPaysString)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "OfferCreate",
|
||||
"Account": wallet.address,
|
||||
"TakerGets": takerGets,
|
||||
"TakerPays": takerPays
|
||||
})
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared)
|
||||
results += "\nSubmitting transaction...."
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
getOffers()
|
||||
client.disconnect()
|
||||
} // End of createOffer()
|
||||
|
||||
/***********************************
|
||||
************ Get Offers ***********
|
||||
**********************************/
|
||||
|
||||
async function getOffers() {
|
||||
let net = getNet()
|
||||
let results = 'Connecting to ' + net + '....\n'
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results += "Connected.\n"
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += accountNameField.value + " account: " + wallet.address
|
||||
// -------------------------------------------------------- Prepare request
|
||||
|
||||
results += '\n\n*** Offers ***\n'
|
||||
let offers
|
||||
try {
|
||||
const offers = await client.request({
|
||||
method: "account_offers",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated"
|
||||
})
|
||||
results += JSON.stringify(offers,null,2)
|
||||
} catch (err) {
|
||||
results += err
|
||||
}
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
}// End of getOffers()
|
||||
|
||||
/***********************************
|
||||
*********** Cancel Offer **********
|
||||
**********************************/
|
||||
|
||||
async function cancelOffer() {
|
||||
let results = "Connecting to the selected ledger.\n"
|
||||
resultField.value = results
|
||||
let net = getNet()
|
||||
results += 'Connecting to ' + net + '....\n'
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
|
||||
results += "Connected.\n"
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += "wallet.address: = " + wallet.address
|
||||
resultField.value = results
|
||||
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
/* OfferSequence is the Seq value when you getOffers. */
|
||||
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "OfferCancel",
|
||||
"Account": wallet.address,
|
||||
"OfferSequence": parseInt(offerSequenceField.value)
|
||||
})
|
||||
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
|
||||
results += "\nBalance changes: \n" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // End of cancelOffer()
|
||||
269
_code-samples/modular-tutorials/create-time-escrow.html
Normal file
269
_code-samples/modular-tutorials/create-time-escrow.html
Normal file
@@ -0,0 +1,269 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Create a Time-based Escrow</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src='create-time-escrow.js'></script>
|
||||
<script>
|
||||
if (typeof module !== "undefined") {
|
||||
const xrpl = require('xrpl')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Create a Time-based Escrow</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Amount of XRP to send.">
|
||||
<label for="amountField">Amount</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="amountField" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Destination account address where the escrow is sent.">
|
||||
<lable for="destinationField">Destination</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="destinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="createTimeBasedEscrow()">Create Time-based Escrow</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow finish time, in seconds.">
|
||||
<lable for="escrowFinishTimeField">Escrow Finish Time</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowFinishTimeField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getEscrows()">Get Escrows</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow cancel time, in seconds.">
|
||||
<lable for="escrowCancelTimeField">Escrow Cancel Time</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowCancelTimeField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="finishTimeBasedEscrow()">Finish Time-based Escrow</button>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow sequence number, used when finishing the escrow.">
|
||||
<lable for="escrowSequenceNumberField">Escrow Sequence Number</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowSequenceNumberField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="cancelEscrow()">Cancel Escrow</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Escrow owner, the account that created the escrow.">
|
||||
<lable for="escrowOwnerField">Escrow Owner</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="escrowOwnerField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getTransaction()">Get Transaction</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Transaction number, used with the Get Transaction button.">
|
||||
<lable for="transactionField">Transaction</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="transactionField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
147
_code-samples/modular-tutorials/create-time-escrow.js
Normal file
147
_code-samples/modular-tutorials/create-time-escrow.js
Normal file
@@ -0,0 +1,147 @@
|
||||
// *******************************************************
|
||||
// ************* Add Seconds to Current Date *************
|
||||
// *******************************************************
|
||||
|
||||
function addSeconds(numOfSeconds, date = new Date()) {
|
||||
date.setSeconds(date.getSeconds() + numOfSeconds);
|
||||
date = Math.floor(date / 1000)
|
||||
date = date - 946684800
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
// *******************************************************
|
||||
// ************* Create Time-based Escrow ****************
|
||||
// *******************************************************
|
||||
|
||||
async function createTimeBasedEscrow() {
|
||||
|
||||
//-------------------------------------------- Prepare Finish and Cancel Dates
|
||||
|
||||
let escrow_finish_date = new Date()
|
||||
let escrow_cancel_date = new Date()
|
||||
escrow_finish_date = addSeconds(parseInt(escrowFinishTimeField.value))
|
||||
escrow_cancel_date = addSeconds(parseInt(escrowCancelTimeField.value))
|
||||
|
||||
//------------------------------------------------------Connect to the Ledger
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}.\nCreating time-based escrow.\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
resultField.value = results
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"FinishAfter": escrow_finish_date,
|
||||
"CancelAfter": escrow_cancel_date
|
||||
})
|
||||
const signed = wallet.sign(escrowTx)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nSuccess! Save this sequence number: " + tx.result.tx_json.Sequence
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
} // End of createTimeEscrow()
|
||||
|
||||
// *******************************************************
|
||||
// ***************** Finish Time- Based Escrow ***********
|
||||
// *******************************************************
|
||||
|
||||
async function finishTimeBasedEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}. Finishing escrow....`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += "\nwallet.address: = " + wallet.address
|
||||
resultField.value = results
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // End of finishTimeBasedEscrow()
|
||||
|
||||
// *******************************************************
|
||||
// ******************* Get Escrows ***********************
|
||||
// *******************************************************
|
||||
|
||||
async function getEscrows() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.\nGetting account escrows...\n`
|
||||
resultField.value = results
|
||||
const escrow_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "escrow"
|
||||
})
|
||||
results += JSON.stringify(escrow_objects.result, null, 2)
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
} // End of getEscrows()
|
||||
|
||||
|
||||
// *******************************************************
|
||||
// ************** Get Transaction Info *******************
|
||||
// *******************************************************
|
||||
|
||||
async function getTransaction() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.\nGetting transaction information...\n`
|
||||
resultField.value = results
|
||||
const tx_info = await client.request({
|
||||
"id": 1,
|
||||
"command": "tx",
|
||||
"transaction": transactionField.value,
|
||||
})
|
||||
results += JSON.stringify(tx_info.result, null, 2)
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
|
||||
} // End of getTransaction()
|
||||
|
||||
// *******************************************************
|
||||
// ****************** Cancel Escrow **********************
|
||||
// *******************************************************
|
||||
|
||||
async function cancelEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}. Cancelling escrow....`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowCancel",
|
||||
"Account": wallet.address,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
}
|
||||
24
_code-samples/modular-tutorials/five-bells.js
Normal file
24
_code-samples/modular-tutorials/five-bells.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const cc = require('five-bells-condition');
|
||||
const crypto = require('crypto');
|
||||
|
||||
// 1. Generate a random 32-byte seed
|
||||
const preimageData = crypto.randomBytes(32);
|
||||
|
||||
// 2. Create a PreimageSha256 fulfillment object
|
||||
const fulfillment = new cc.PreimageSha256();
|
||||
|
||||
// 3. Set the preimage
|
||||
fulfillment.setPreimage(preimageData);
|
||||
|
||||
// 4. Generate the condition (binary)
|
||||
const conditionBinary = fulfillment.getConditionBinary();
|
||||
|
||||
// 5. Generate the fulfillment (binary)
|
||||
const fulfillmentBinary = fulfillment.serializeBinary();
|
||||
|
||||
// Convert to hex for easier use
|
||||
const conditionHex = conditionBinary.toString('hex').toUpperCase();
|
||||
const fulfillmentHex = fulfillmentBinary.toString('hex').toUpperCase();
|
||||
|
||||
console.log('Condition (hex):', conditionHex);
|
||||
console.log('Fulfillment (hex):', fulfillmentHex);
|
||||
150
_code-samples/modular-tutorials/modular-tutorials.css
Normal file
150
_code-samples/modular-tutorials/modular-tutorials.css
Normal file
@@ -0,0 +1,150 @@
|
||||
body {
|
||||
font-family: "Inter", sans-serif;
|
||||
padding: 20px;
|
||||
background: #abe2ff;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
td {
|
||||
padding-left: 25px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
padding: 6px;
|
||||
margin-bottom: 8px;
|
||||
border: none
|
||||
}
|
||||
|
||||
input:read-only {
|
||||
background-color:rgb(11, 96, 132);
|
||||
color:white;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
font-weight: bold;
|
||||
font-family: "Work Sans", sans-serif;
|
||||
background-color: #006aff;
|
||||
-webkit-text-fill-color: white;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0555c5;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* The switch - the box around the slider */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
/* Hide default HTML checkbox */
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* The slider */
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 13px;
|
||||
width: 13px;
|
||||
left: 4px;
|
||||
bottom: 2px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
input:checked+.slider {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
|
||||
input:focus+.slider {
|
||||
box-shadow: 0 0 1px #2196F3;
|
||||
}
|
||||
|
||||
input:checked+.slider:before {
|
||||
-webkit-transform: translateX(13px);
|
||||
-ms-transform: translateX(13px);
|
||||
transform: translateX(13px);
|
||||
}
|
||||
|
||||
/* Rounded sliders */
|
||||
.slider.round {
|
||||
border-radius: 17px;
|
||||
}
|
||||
|
||||
.slider.round:before {
|
||||
border-radius: 50%;
|
||||
}
|
||||
.tooltip {
|
||||
position: relative;
|
||||
border-bottom: 1px dotted black;
|
||||
}
|
||||
|
||||
.tooltip:before {
|
||||
content: attr(tooltip-data);
|
||||
position: absolute;
|
||||
width: 250px;
|
||||
background-color: #006aff;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
padding: 15px;
|
||||
line-height: 1.1;
|
||||
border-radius: 5px;
|
||||
z-index: 1;
|
||||
opacity: 0;
|
||||
transition: opacity .5s;
|
||||
bottom: 125%;
|
||||
left: 50%;
|
||||
margin-left: -60px;
|
||||
font-size: 0.70em;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.tooltip:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: 75%;
|
||||
left: 50%;
|
||||
margin-left: -5px;
|
||||
border-width: 5px;
|
||||
border-style: solid;
|
||||
opacity: 0;
|
||||
transition: opacity .5s;
|
||||
border-color: #000 transparent transparent transparent;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.tooltip:hover:before,
|
||||
.tooltip:hover:after {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
BIN
_code-samples/modular-tutorials/payment-modular-tutorials.zip
Normal file
BIN
_code-samples/modular-tutorials/payment-modular-tutorials.zip
Normal file
Binary file not shown.
247
_code-samples/modular-tutorials/send-checks.html
Normal file
247
_code-samples/modular-tutorials/send-checks.html
Normal file
@@ -0,0 +1,247 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Send Checks</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src='send-xrp.js'></script>
|
||||
<script src='send-currency.js'></script>
|
||||
<script src='send-checks.js'></script>
|
||||
<script>
|
||||
if (typeof module !== "undefined") {
|
||||
const xrpl = require('xrpl')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Send Checks</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Currency code for the check.">
|
||||
<lable for="currencyField">Currency Code</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="currencyField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="sendCheck()">Send Check</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Issuing account for the currency.">
|
||||
<lable for="issuerField">Issuer</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="issuerField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="cashCheck()">Cash Check</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Amount of XRP to send.">
|
||||
<label for="amountField">Amount</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="amountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getChecks()">Get Checks</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Destination account address where XRP is sent.">
|
||||
<lable for="destinationField">Destination</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="destinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="cancelCheck()">Cancel Check</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Check ID.">
|
||||
<lable for="checkIdField">Check ID</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="checkIdField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getTokenBalance()">Get Token Balance</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
139
_code-samples/modular-tutorials/send-checks.js
Normal file
139
_code-samples/modular-tutorials/send-checks.js
Normal file
@@ -0,0 +1,139 @@
|
||||
// *******************************************************
|
||||
// ***************** Send Check **************************
|
||||
// *******************************************************
|
||||
async function sendCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
let check_amount = amountField.value
|
||||
if (currencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"currency": currencyField.value,
|
||||
"value": amountField.value,
|
||||
"issuer": wallet.address
|
||||
}
|
||||
}
|
||||
const send_check_tx = {
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": wallet.address,
|
||||
"SendMax": check_amount,
|
||||
"Destination": destinationField.value
|
||||
}
|
||||
const check_prepared = await client.autofill(send_check_tx)
|
||||
const check_signed = wallet.sign(check_prepared)
|
||||
results += '\nSending ' + amountField.value + ' ' + currencyField.value + ' to ' +
|
||||
destinationField.value + '...\n'
|
||||
resultField.value = results
|
||||
const check_result = await client.submitAndWait(check_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded:\n'
|
||||
resultField.value += JSON.stringify(check_result.result, null, 2)
|
||||
} else {
|
||||
results += `Error sending transaction: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of sendCheck()
|
||||
|
||||
// *******************************************************
|
||||
// ********************* Get Checks **********************
|
||||
// *******************************************************
|
||||
|
||||
async function getChecks() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
const check_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "check"
|
||||
})
|
||||
resultField.value = JSON.stringify(check_objects.result, null, 2)
|
||||
client.disconnect()
|
||||
} // End of getChecks()
|
||||
|
||||
// *******************************************************
|
||||
// ******************** Cash Check **********************
|
||||
// *******************************************************
|
||||
|
||||
async function cashCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
var check_amount = amountField.value
|
||||
|
||||
if (currencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"value": amountField.value,
|
||||
"currency": currencyField.value,
|
||||
"issuer": issuerField.value
|
||||
}
|
||||
}
|
||||
const cash_check_tx = {
|
||||
"TransactionType": "CheckCash",
|
||||
"Account": wallet.address,
|
||||
"Amount": check_amount,
|
||||
"CheckID": checkIdField.value
|
||||
}
|
||||
const cash_prepared = await client.autofill(cash_check_tx)
|
||||
const cash_signed = wallet.sign(cash_prepared)
|
||||
results += ' Receiving ' + amountField.value + ' ' + currencyField.value + '.\n'
|
||||
resultField.value = results
|
||||
const check_result = await client.submitAndWait(cash_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded:\n' + JSON.stringify(check_result.result, null, 2)
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `Error sending transaction: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of cashCheck()
|
||||
|
||||
// *******************************************************
|
||||
// **************** Cancel Check *************************
|
||||
// *******************************************************
|
||||
|
||||
async function cancelCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
|
||||
const cancel_check_tx = {
|
||||
"TransactionType": "CheckCancel",
|
||||
"Account": wallet.address,
|
||||
"CheckID": checkIdField.value
|
||||
}
|
||||
const cancel_prepared = await client.autofill(cancel_check_tx)
|
||||
const cancel_signed = wallet.sign(cancel_prepared)
|
||||
results += ' Cancelling check.\n'
|
||||
resultField.value = results
|
||||
const check_result = await client.submitAndWait(cancel_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += `Transaction succeeded: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `Error sending transaction: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of cancelCheck()
|
||||
229
_code-samples/modular-tutorials/send-currency.html
Normal file
229
_code-samples/modular-tutorials/send-currency.html
Normal file
@@ -0,0 +1,229 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Send Currency</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src='send-xrp.js'></script>
|
||||
<script src='send-currency.js'></script>
|
||||
<script>
|
||||
if (typeof module !== "undefined") {
|
||||
const xrpl = require('xrpl')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Send Currency</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Currency code for the trust line.">
|
||||
<lable for="currencyField">Currency Code</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="currencyField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="createTrustLine()">Create Trust Line</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Issuing account for the currency.">
|
||||
<lable for="issuerField">Issuer</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="issuerField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="sendCurrency()">Send Currency</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Amount of XRP to send.">
|
||||
<label for="amountField">Amount</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="amountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getTokenBalance()">Get Token Balance</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Destination account address where XRP is sent.">
|
||||
<lable for="destinationField">Destination</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="destinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
const radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
72
_code-samples/modular-tutorials/send-currency.js
Normal file
72
_code-samples/modular-tutorials/send-currency.js
Normal file
@@ -0,0 +1,72 @@
|
||||
// *******************************************************
|
||||
// ***************** Create TrustLine ********************
|
||||
// *******************************************************
|
||||
|
||||
async function createTrustLine() {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = "\nConnected. Creating trust line.\n"
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const trustSet_tx = {
|
||||
"TransactionType": "TrustSet",
|
||||
"Account": accountAddressField.value,
|
||||
"LimitAmount": {
|
||||
"currency": currencyField.value,
|
||||
"issuer": issuerField.value,
|
||||
"value": amountField.value
|
||||
}
|
||||
}
|
||||
const ts_prepared = await client.autofill(trustSet_tx)
|
||||
const ts_signed = wallet.sign(ts_prepared)
|
||||
resultField.value = results
|
||||
const ts_result = await client.submitAndWait(ts_signed.tx_blob)
|
||||
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += '\nTrustline established between account \n' +
|
||||
accountAddressField.value + ' \n and account\n' + issuerField.value + '.'
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${ts_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
} //End of createTrustline()
|
||||
|
||||
// *******************************************************
|
||||
// *************** Send Issued Currency ******************
|
||||
// *******************************************************
|
||||
|
||||
async function sendCurrency() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
resultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const send_currency_tx = {
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": {
|
||||
"currency": currencyField.value,
|
||||
"value": amountField.value,
|
||||
"issuer": issuerField.value
|
||||
},
|
||||
"Destination": destinationField.value
|
||||
}
|
||||
const pay_prepared = await client.autofill(send_currency_tx)
|
||||
const pay_signed = wallet.sign(pay_prepared)
|
||||
results += `\n\nSending ${amountField.value} ${currencyField.value} to ${destinationField.value} ...`
|
||||
resultField.value = results
|
||||
const pay_result = await client.submitAndWait(pay_signed.tx_blob)
|
||||
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded.'
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${pay_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of sendCurrency()
|
||||
218
_code-samples/modular-tutorials/send-mpt.html
Normal file
218
_code-samples/modular-tutorials/send-mpt.html
Normal file
@@ -0,0 +1,218 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Send MPT</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<link href="modular-tutorials.css" rel="stylesheet">
|
||||
<script src='https://unpkg.com/xrpl@4.1.0/build/xrpl-latest.js'></script>
|
||||
<script src="account-support.js"></script>
|
||||
<script src='send-mpt.js'></script>
|
||||
<script>
|
||||
if (typeof module !== "undefined") {
|
||||
const xrpl = require('xrpl')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Send MPT</h1>
|
||||
<form id="theForm">
|
||||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
|
||||
Choose your ledger instance:
|
||||
</span>
|
||||
|
||||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
|
||||
<label for="dn">Devnet</label>
|
||||
|
||||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
|
||||
<label for="tn">Testnet</label>
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1name" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
|
||||
<label for="account2name">Account 2 Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2name" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account1address">Account 1 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1address" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Identifying address for the account.">
|
||||
<label for="account2address">Account 2 Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2address" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account1seed">Account 1 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account1seed" size="40"></input>
|
||||
</td>
|
||||
<td>
|
||||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
|
||||
<label for="account2seed">Account 2 Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="account2seed" size="40"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Name of the currently selected account.">
|
||||
<label for="accountNameField">Account Name</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountNameField" size="40" readonly></input>
|
||||
<input type="radio" id="account1" name="accounts" value="account1">
|
||||
<label for="account1">Account 1</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Address of the currently selected account.">
|
||||
<label for="accountAddressField">Account Address</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountAddressField" size="40" readonly></input>
|
||||
<input type="radio" id="account2" name="accounts" value="account2">
|
||||
<label for="account2">Account 2</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
|
||||
<label for="accountSeedField">Account Seed</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="accountSeedField" size="40" readonly></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
|
||||
<label for="xrpBalanceField">XRP Balance</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="xrpBalanceField" size="40" readonly></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Issuance ID of the MPT you want to trade.">
|
||||
<lable for="mptIdField">MPT Issuance ID</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="mptIdField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="authorizeMPT()">Authorize MPT</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Number of MPTs to send.">
|
||||
<label for="amountField">Amount</label>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="amountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" onClick="sendMPT()">Send MPT</button>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
<span class="tooltip" tooltip-data="Destination account address for MPT transfer.">
|
||||
<lable for="destinationField">Destination</lable>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="destinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="getMPTs()">Get MPTs</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p align="right">
|
||||
<textarea id="resultField" cols="80" rows="20"></textarea>
|
||||
</p>
|
||||
</td>
|
||||
<td align="left" valign="top">
|
||||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
|
||||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
let radioButtons = document.querySelectorAll('input[type="radio"]');
|
||||
radioButtons.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'account1') {
|
||||
populate1()
|
||||
} else if (this.value === 'account2') {
|
||||
populate2()
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
101
_code-samples/modular-tutorials/send-mpt.js
Normal file
101
_code-samples/modular-tutorials/send-mpt.js
Normal file
@@ -0,0 +1,101 @@
|
||||
// *******************************************************
|
||||
// ********************* Send MPT ************************
|
||||
// *******************************************************
|
||||
|
||||
async function sendMPT() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}....`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpt_issuance_id = mptIdField.value
|
||||
const mpt_quantity = amountField.value
|
||||
const send_mpt_tx = {
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": {
|
||||
"mpt_issuance_id": mpt_issuance_id,
|
||||
"value": mpt_quantity,
|
||||
},
|
||||
"Destination": destinationField.value,
|
||||
}
|
||||
const pay_prepared = await client.autofill(send_mpt_tx)
|
||||
const pay_signed = wallet.sign(pay_prepared)
|
||||
results += `\n\nSending ${mpt_quantity} ${mpt_issuance_id} to ${destinationField.value} ...`
|
||||
resultField.value = results
|
||||
const pay_result = await client.submitAndWait(pay_signed.tx_blob)
|
||||
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded.\n\n'
|
||||
results += JSON.stringify(pay_result.result, null, 2)
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${pay_result.result.meta.TransactionResult}\n\n`
|
||||
results += JSON.stringify(pay_result.result, null, 2)
|
||||
resultField.value = results
|
||||
}
|
||||
client.disconnect()
|
||||
} // end of sendMPT()
|
||||
|
||||
// *******************************************************
|
||||
// ******************** Get MPTs *************************
|
||||
// *******************************************************
|
||||
|
||||
async function getMPTs() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
let results = `Connected to ${net}....`
|
||||
resultField.value = results
|
||||
const mpts = await client.request({
|
||||
command: "account_objects",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated",
|
||||
type: "mptoken"
|
||||
})
|
||||
let JSONString = JSON.stringify(mpts.result, null, 2)
|
||||
let JSONParse = JSON.parse(JSONString)
|
||||
let numberOfMPTs = JSONParse.account_objects.length
|
||||
let x = 0
|
||||
while (x < numberOfMPTs){
|
||||
results += "\n\nMPT Issuance ID: " + JSONParse.account_objects[x].MPTokenIssuanceID
|
||||
+ "\nMPT Amount: " + JSONParse.account_objects[x].MPTAmount
|
||||
x++
|
||||
}
|
||||
results += "\n\n" + JSONString
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
} // End of getMPTs()
|
||||
|
||||
// **********************************************************************
|
||||
// ****** MPTAuthorize Transaction ***************************************
|
||||
// **********************************************************************
|
||||
|
||||
async function authorizeMPT() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}....`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpt_issuance_id = mptIdField.value
|
||||
const auth_mpt_tx = {
|
||||
"TransactionType": "MPTokenAuthorize",
|
||||
"Account": wallet.address,
|
||||
"MPTokenIssuanceID": mpt_issuance_id,
|
||||
}
|
||||
const auth_prepared = await client.autofill(auth_mpt_tx)
|
||||
const auth_signed = wallet.sign(auth_prepared)
|
||||
results += `\n\nSending authorization...`
|
||||
resultField.value = results
|
||||
const auth_result = await client.submitAndWait(auth_signed.tx_blob)
|
||||
if (auth_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += `\nTransaction succeeded`
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${auth_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
client.disconnect()
|
||||
} // end of MPTAuthorize()
|
||||
28
_code-samples/modular-tutorials/send-xrp.js
Normal file
28
_code-samples/modular-tutorials/send-xrp.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// *******************************************************
|
||||
// ******************** Send XRP *************************
|
||||
// *******************************************************
|
||||
async function sendXRP() {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = "\nConnected. Sending XRP.\n"
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
const prepared_tx = await client.autofill({
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value
|
||||
})
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared_tx)
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results = "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // End of sendXRP()
|
||||
Reference in New Issue
Block a user