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.
<div class="container">
<h5>Estimate transaction fee</h5>
Transfer 1 wei vet & 1 wei vtho cost in different priority
<div class="card-group">
<div class="card">
<div class="card-body">
<h5 class="card-title">Regular</h5>
<p class="card-text text-primary" id="regular">-- VTHO</p>
</div>
<div class="card-footer">
<small class="text-muted" id="regularGas">GasPriceCoef: 0</small>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Medium</h5>
<p class="card-text text-success" id="medium">-- VTHO</p>
</div>
<div class="card-footer">
<small class="text-muted">GasPriceCoef: 85</small>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">High</h5>
<p class="card-text text-info" id="high">-- VTHO</p>
</div>
<div class="card-footer">
<small class="text-muted">GasPriceCoef: 255</small>
</div>
</div>
</div>
<br>
<pre id="bgp">BaseGasePrice: --</pre>
<pre id="vmUsed">Vm gasUsed: --</pre>
<pre id="intrinsic">IntrinsicGas: --</pre>
<pre id="totalGas">Total Gas: --</pre>
<a href="https://docs.vechain.org/thor/learn/transaction-calculation.html">Ref: Transaction fee calculation</a>
</div>
.container {
width: 80%;
}
const connex = new Connex({
node: "https://testnet.veblocks.net/",
network: "test"
});
const transferABI = {
constant: false,
inputs: [
{
name: "_to",
type: "address"
},
{
name: "_amount",
type: "uint256"
}
],
name: "transfer",
outputs: [
{
name: "success",
type: "bool"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
};
const paramsABI = {
constant: true,
inputs: [
{
name: "_key",
type: "bytes32"
}
],
name: "get",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
};
async function getBaseGasPrice() {
const baseGasPriceMethod = connex.thor
// params contract address
.account("0x0000000000000000000000000000506172616d73")
.method(paramsABI);
const outputs = await baseGasPriceMethod.call(
//0x000000…696365 is the key of baseGasPrice https://docs.vechain.org/others/miscellaneous.html#key-of-governance-params
"0x000000000000000000000000000000000000626173652d6761732d7072696365"
);
return outputs.decoded[0];
}
//get vm gas used
async function vmGasUsed(clauses) {
const exp = connex.thor.explain(clauses);
const outputs = await exp
// Set maximum gas
.gas(20000000)
// Set caller
.caller("0x8a259d8684E88e063EaA2213a7a390A725065c65")
.execute();
return outputs.reduce((sum, out) => sum + out.gasUsed, 0);
}
async function estimateTxFee() {
//Create clauses of transferring VET & VTHO
const transferMethod = connex.thor
.account("0x0000000000000000000000000000456E65726779")
.method(transferABI);
// Alice's address transfer 1 wei vtho
const vthoClause = transferMethod.asClause(
"0xd3ae78222beadb038203be21ed5ce7c9b1bff602",
1
);
//Alice address transfer 1 wei vet
const vetClause = {
to: "0xd3ae78222beadb038203be21ed5ce7c9b1bff602",
value: 1,
data: "0x486170707920636f64696e6720f09f8e89"
};
const clauses = [vetClause, vthoClause];
const intrinsic = intrinsicGas(clauses);
const baseGasPrice = await getBaseGasPrice();
const vmUsed = await vmGasUsed(clauses);
updateUI(intrinsic, baseGasPrice, vmUsed);
}
estimateTxFee();
function updateUI(intrinsic, baseGasPrice, vmUsed) {
//adding some extra gas to make sure the transaction go through
const gas = new BigNumber(intrinsic).plus(vmUsed).plus(15000);
//priority regular = gasPriceCoef 0/255
const regularCost = calcFee(gas, baseGasPrice, 0).toFixed(2);
//priority medium = gasPriceCoef 85/255
const mediumCost = calcFee(gas, baseGasPrice, 85).toFixed(2);
//priority high = gasPriceCoef 255/255
const highCost = calcFee(gas, baseGasPrice, 255).toFixed(2);
document.getElementById("regular").innerText = regularCost + " VTHO";
document.getElementById("medium").innerText = mediumCost + " VTHO";
document.getElementById("high").innerText = highCost + " VTHO";
const vtho = BigNumber(1e18).dividedBy(baseGasPrice);
document.getElementById("totalGas").innerText = "Total Gas: " + gas + " gas";
document.getElementById("bgp").innerText =
"BaseGasePrice:" + baseGasPrice + " (1 VTHO = " + vtho + " gas)";
document.getElementById("vmUsed").innerText =
"Vm gasUsed: " + vmUsed + " gas";
document.getElementById("intrinsic").innerText =
"IntrinsicGas: " + intrinsic + " gas";
}
function intrinsicGas(clauses) {
const txGas = 5000;
const clauseGas = 16000;
const clauseGasContractCreation = 48000;
if (clauses.length === 0) {
return txGas + clauseGas;
}
return clauses.reduce((sum, c) => {
if (c.to) {
sum += clauseGas;
} else {
sum += clauseGasContractCreation;
}
sum += dataGas(c.data);
return sum;
}, txGas);
}
function dataGas(data) {
const zgas = 4;
const nzgas = 68;
let sum = 0;
for (let i = 2; i < data.length; i += 2) {
if (data.substr(i, 2) === "00") {
sum += zgas;
} else {
sum += nzgas;
}
}
return sum;
}
function calcFee(gas, baseGasPrice, gasPriceCoef) {
return new BigNumber(baseGasPrice)
.times(gasPriceCoef)
.idiv(255)
.plus(baseGasPrice)
.times(gas)
.dividedBy(1e18);
}
Also see: Tab Triggers