HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<html>
<head>
<title>XRPL Token Test Harness</title>
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
<script src='https://unpkg.com/xrpl@2.6.0'></script>
<script>
if (typeof module !== "undefined") {
const xrpl = require('xrpl')
}
</script>
</head>
<body>
<div id="selectLedger">
<div class="appField">
<strong>Choose your ledger instance:</strong><br />
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233" checked>
<label for="testnet">Testnet</label>
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233">
<label for="devnet">Devnet</label>
</div>
<div class="appField">
<button type="button" onClick="getAccountsFromSeeds()">Get Accounts From Seeds</button><br />
<textarea id="seeds" cols="40" rows="2"></textarea>
</div>
</div>
<div id="flexContainer">
<div class="flexColumn">
<div id="standbyApp">
<button type="button" onClick="getAccount('standby')">Create Standby Account</button><br />
<h2>Standby Account Info</h2>
<div class="appField">Account<br />
<div id="standbyAccountField" class="appValue"></div>
</div>
<div class="appField">Public Key<br />
<div id="standbyPubKeyField" class="appValue"></div>
</div>
<div class="appField">Private Key<br />
<div id="standbyPrivKeyField" class="appValue"></div>
</div>
<div class="appField"> Seed<br />
<div id="standbySeedField" class="appValue"></div>
</div>
<div class="appField"> XRP Balance<br />
<div id="standbyBalanceField" class="appValue"></div>
</div>
<div id="standbyTransact">
<p><strong>Send XRP or Currency</strong></p>
<div class="appField">
Amount<br />
<input id="standbyAmountField" class="appValue"></input>
</div>
<div class="appField">
Destination Account <br />
<input id="standbyDestinationField" class="appValue"></input>
</div>
<div class="appField">
Currency<br />
<input type="text" class="appValue" id="standbyCurrencyField" size="30" value="USD"></input>
</div>
<br /><br />
<button type="button" onClick="configureAccount('standby',document.querySelector('#standbyDefault').checked)">Configure Account</button><br />
<input type="checkbox" id="standbyDefault" checked="true" />
<label for="standbyDefault">Allow Rippling</label>
<p>
<button type="button" onClick="createTrustline()">Create TrustLine</button>
<button type="button" onClick="sendCurrency()">Send Currency</button>
<button type="button" onClick="getBalances()">Get Balances</button>
<button type="button" onClick="sendXRP()">Send XRP →</button>
</p>
<p><strong>Transaction Log</strong></p>
<div id="standbyResultField"></div>
</div>
</div>
</div>
<div class="flexColumn">
<div id="operationalApp">
<button type="button" onClick="getAccount('operational')">Create Operational Account</button><br />
<h2>Operational Account Info</h2>
<div class="appField">Account<br />
<div id="operationalAccountField" class="appValue"></div>
</div>
<div class="appField">Public Key<br />
<div id="operationalPubKeyField" class="appValue"></div>
</div>
<div class="appField">Private Key<br />
<div id="operationalPrivKeyField" class="appValue"></div>
</div>
<div class="appField"> Seed<br />
<div id="operationalSeedField" class="appValue"></div>
</div>
<div class="appField"> XRP Balance<br />
<div id="operationalBalanceField" class="appValue"></div>
</div>
<div id="operationalTransact">
<p><strong>Send XRP</strong></p>
<div class="appField">
Amount<br />
<input id="operationalAmountField" class="appValue"></input>
</div>
<div class="appField">
Destination Account <br />
<input id="operationalDestinationField" class="appValue"></input>
</div>
<div class="appField">
Currency<br />
<input type="text" class="appValue" id="operationalCurrencyField" size="30" value="USD"></input>
</div>
<br /><br />
<button type="button" onClick="configureAccount('standby',document.querySelector('#standbyDefault').checked)">Configure Account</button><br />
<input type="checkbox" id="operationalDefault" checked="true" />
<label for="operationalDefault">Allow Rippling</label>
<p>
<button type="button" onClick="oPcreateTrustline()">Create TrustLine</button>
<button type="button" onClick="oPsendCurrency()">Send Currency</button>
<button type="button" onClick="oPgetBalances()">Get Balances</button>
<button type="button" onClick="oPsendXRP()"> ← Send XRP</button>
</p>
<p><strong>Transaction Log</strong></p>
<div id="operationalResultField"></div>
</div>
</div>
</div>
</div>
</body>
</html>
body {
font-family: "Work Sans", sans-serif;
padding: 40px;
background: #fafafa;
font-size: 0.8em;
}
h1 {
font-weight: bold;
}
button {
padding: 12px;
margin-bottom: 8px;
font-size: 1em;
background: #fff;
border-radius: 0.5em;
border: solid 2px #444;
}
button {
font-weight: bold;
font-family: "Work Sans", sans-serif;
}
button:hover {
background: #eee;
cursor: pointer;
}
td {
vertical-align: top;
padding-right: 10px;
}
#selectLedger {
background: #ff78bb;
padding: 1em 1em 0 1em;
border-radius: 1em;
width: 80%;
margin: 0 0 1em 0;
font-size: 1.25em;
line-height: 2em;
}
.appField {
vertical-align: top;
display: inline-block;
margin: 0 1em 0 0;
}
.appValue {
display: inline-block;
overflow-wrap: break-word;
padding: 0.25em;
height: 2.5em;
font-size: 10px;
background: #efefef;
min-width: 100px;
max-width: 300px;
border-radius: 0.5em;
margin: 0.25em 0 0.5em 0;
}
#flexContainer {
display: flex;
align-content: flex-start;
margin: 0 -0.5em;
}
.flexColumn {
width: 100%;
flex: 1 0 50%;
max-width: 50%;
margin: 0 0.5em;
}
#standbyApp {
background: #86e3b0;
padding: 1.5em;
border-radius: 1em;
}
#standbyTransact {
display: inline-block;
background: #42df89;
border-radius: 0.5em;
display: inline-block;
margin: 0.5em 0;
padding: 0 1.5em;
min-width: 90%;
}
#standbyResultField {
display: inline-block;
padding: 0.25em;
border: solid 1px white;
height: 2em;
font-size: 1em;
background: #efefef;
width: 100%;
border-radius: 3px;
margin: 0.25em 0 0.5em 0;
height: 100px;
overflow-y: scroll;
}
#operationalApp {
background: #58bbfd;
padding: 1.5em;
border-radius: 1em;
}
#operationalTransact {
display: inline-block;
background: #19a3ff;
border-radius: 0.5em;
display: inline-block;
margin: 0.5em 0;
padding: 0 1.5em;
min-width: 90%;
}
#operationalResultField {
display: inline-block;
padding: 0.25em;
border: solid 1px white;
height: 2em;
font-size: 1em;
background: #efefef;
width: 100%;
border-radius: 3px;
margin: 0.25em 0 0.5em 0;
height: 100px;
overflow-y: scroll;
}
input {
border: none;
}
// **************** Configure Account ********************
async function configureAccount(type, rippleDefault) {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
standbyResultField.innerHTML = results;
await client.connect();
results += "<br/>Connected, finding wallet.";
standbyResultField.innerHTML = results;
if (type == "standby") {
my_wallet = xrpl.Wallet.fromSeed(standbySeedField.innerHTML);
} else {
my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.innerHTML);
}
results += "Ripple Default Setting: " + rippleDefault;
standbyResultField.innerHTML = results;
let settings_tx = {};
if (rippleDefault) {
settings_tx = {
TransactionType: "AccountSet",
Account: my_wallet.address,
SetFlag: xrpl.AccountSetAsfFlags.asfDefaultRipple
};
results += "<br/> Set Default Ripple flag.";
} else {
settings_tx = {
TransactionType: "AccountSet",
Account: my_wallet.address,
ClearFlag: xrpl.AccountSetAsfFlags.asfDefaultRipple
};
results += "<br/> Clear Default Ripple flag.";
}
results += "<br/>Sending account setting.";
standbyResultField.innerHTML = results;
const cst_prepared = await client.autofill(settings_tx);
const cst_signed = my_wallet.sign(cst_prepared);
const cst_result = await client.submitAndWait(cst_signed.tx_blob);
if (cst_result.result.meta.TransactionResult == "tesSUCCESS") {
results += "<br/>Account setting succeeded.";
standbyResultField.innerHTML = results;
} else {
throw "Error sending transaction: ${cst_result}";
results += "<br/>Account setting failed.";
standbyResultField.innerHTML = results;
}
client.disconnect();
} // End of configureAccount()
// *******************************************************
// ***************** Create TrustLine ********************
// *******************************************************
async function createTrustline() {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
standbyResultField.innerHTML = results;
await client.connect();
results += "<br/>Connected.";
standbyResultField.innerHTML = results;
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.innerHTML);
const operational_wallet = xrpl.Wallet.fromSeed(
operationalSeedField.innerHTML
);
const currency_code = standbyCurrencyField.value;
const trustSet_tx = {
TransactionType: "TrustSet",
Account: standbyDestinationField.value,
LimitAmount: {
currency: standbyCurrencyField.value,
issuer: standby_wallet.address,
value: standbyAmountField.value
}
};
const ts_prepared = await client.autofill(trustSet_tx);
const ts_signed = operational_wallet.sign(ts_prepared);
results +=
"<br/>Creating trust line from operational account to standby account...";
standbyResultField.innerHTML = results;
const ts_result = await client.submitAndWait(ts_signed.tx_blob);
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
results +=
"<br/>Trustline established between account <br/>" +
standbyDestinationField.value +
" <br/> and account<br/>" +
standby_wallet.address +
".";
standbyResultField.innerHTML = results;
} else {
results += "<br/>TrustLine failed. See JavaScript console for details.";
standbyResultField.innerHTML = results;
throw "Error sending transaction: ${ts_result.result.meta.TransactionResult}";
}
} //End of createTrustline()
// *******************************************************
// *************** Send Issued Currency ******************
// *******************************************************
async function sendCurrency() {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
standbyResultField.innerHTML = results;
await client.connect();
results += "<br/>Connected.";
standbyResultField.value = results;
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.innerHTML);
const operational_wallet = xrpl.Wallet.fromSeed(
operationalSeedField.innerHTML
);
const currency_code = standbyCurrencyField.value;
const issue_quantity = standbyAmountField.value;
const send_token_tx = {
TransactionType: "Payment",
Account: standby_wallet.address,
Amount: {
currency: standbyCurrencyField.value,
value: standbyAmountField.value,
issuer: standby_wallet.address
},
Destination: standbyDestinationField.value
};
const pay_prepared = await client.autofill(send_token_tx);
const pay_signed = standby_wallet.sign(pay_prepared);
results +=
"Sending " +
standbyAmountField.value +
standbyCurrencyField.value +
"to " +
standbyDestinationField.value +
"...";
standbyResultField.innerHTML = results;
const pay_result = await client.submitAndWait(pay_signed.tx_blob);
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
results +=
"Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}";
standbyResultField.innerHTML = results;
} else {
results += "Transaction failed: See JavaScript console for details.";
standbyResultField.innerHTML = results;
throw "Error sending transaction: ${pay_result.result.meta.TransactionResult}";
}
standbyBalanceField.innerHTML = await client.getXrpBalance(
standby_wallet.address
);
operationalBalanceField.innerHTML = await client.getXrpBalance(
operational_wallet.address
);
getBalances();
client.disconnect();
} // end of sendIOU()
// *******************************************************
// ****************** Get Balances ***********************
// *******************************************************
async function getBalances() {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
standbyResultField.innerHTML = results;
await client.connect();
results += "<br/>Connected.";
standbyResultField.innerHTML = results;
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.innerHTML);
const operational_wallet = xrpl.Wallet.fromSeed(
operationalSeedField.innerHTML
);
results = "<br/>Getting standby account balances...<br/>";
const standby_balances = await client.request({
command: "gateway_balances",
account: standby_wallet.address,
ledger_index: "validated",
hotwallet: [operational_wallet.address]
});
results += JSON.stringify(standby_balances.result, null, 2);
standbyResultField.innerHTML = results;
results = "<br/>Getting operational account balances...<br/>";
const operational_balances = await client.request({
command: "account_lines",
account: operational_wallet.address,
ledger_index: "validated"
});
results += JSON.stringify(operational_balances.result, null, 2);
operationalResultField.innerHTML = results;
operationalBalanceField.innerHTML = await client.getXrpBalance(
operational_wallet.address
);
standbyBalanceField.innerHTML = await client.getXrpBalance(
standby_wallet.address
);
client.disconnect();
} // End of getBalances()
// **********************************************************************
// ****** Reciprocal Transactions ***************************************
// **********************************************************************
// *******************************************************
// ************ Create Operational TrustLine *************
// *******************************************************
async function oPcreateTrustline() {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
operationalResultField.innerHTML = results;
await client.connect();
results += "<br/>Connected.";
operationalResultField.innerHTML = results;
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.innerHTML);
const operational_wallet = xrpl.Wallet.fromSeed(
operationalSeedField.innerHTML
);
const trustSet_tx = {
TransactionType: "TrustSet",
Account: operationalDestinationField.value,
LimitAmount: {
currency: operationalCurrencyField.value,
issuer: operational_wallet.address,
value: operationalAmountField.value
}
};
const ts_prepared = await client.autofill(trustSet_tx);
const ts_signed = standby_wallet.sign(ts_prepared);
results +=
"<br/>Creating trust line from operational account to " +
operationalDestinationField.value +
" account...";
operationalResultField.innerHTML = results;
const ts_result = await client.submitAndWait(ts_signed.tx_blob);
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
results +=
"<br/>Trustline established between account <br/>" +
standby_wallet.address +
" <br/> and account<br/>" +
operationalDestinationField.value +
".";
operationalResultField.innerHTML = results;
} else {
results += "<br/>TrustLine failed. See JavaScript console for details.";
operationalResultField.innerHTML = results;
throw "Error sending transaction: ${ts_result.result.meta.TransactionResult}";
}
} //End of oPcreateTrustline
// *******************************************************
// ************* Operational Send Issued Currency ********
// *******************************************************
async function oPsendCurrency() {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
operationalResultField.value = results;
await client.connect();
results += "<br/>Connected.";
operationalResultField.innerHTML = results;
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value);
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value);
const currency_code = operationalCurrencyField.value;
const issue_quantity = operationalAmountField.value;
const send_token_tx = {
TransactionType: "Payment",
Account: operational_wallet.address,
Amount: {
currency: currency_code,
value: issue_quantity,
issuer: operational_wallet.address
},
Destination: operationalDestinationField.value
};
const pay_prepared = await client.autofill(send_token_tx);
const pay_signed = operational_wallet.sign(pay_prepared);
results +=
"Sending" +
operationalAmountField.value +
operationalCurrencyField.value +
" to " +
operationalDestinationField.value +
"...";
operationalResultField.innerHTML = results;
const pay_result = await client.submitAndWait(pay_signed.tx_blob);
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
results +=
"Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}";
operationalResultField.innerHTML = results;
} else {
results += "Transaction failed: See JavaScript console for details.";
operationalResultField.innerHTML = results;
throw "Error sending transaction: ${pay_result.result.meta.TransactionResult}";
}
standbyBalanceField.innerHTML = await client.getXrpBalance(
standby_wallet.address
);
operationalBalanceField.innerHTML = await client.getXrpBalance(
operational_wallet.address
);
getBalances();
client.disconnect();
} // end of oPsendCurrency()
Also see: Tab Triggers