Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /*
README

SatoshiDice has a new address bc1quykuahxrjx6d3h6ga4rkyg0hl5e59tcthqyhw6.
Send up to .2 BTC to this address and have a 50% chance to 1.98x your money.
If you win, the money will be sent to the change address and if there is no change address, the first input address.
Your winnings will be 1.98x your original bet minus 0.00001 btc for fees.

The provably fair number is generated from blockhash of the tx + next blockhash + next blockhash + next blockhash + txid.
The following script will generate the a number between 0 and 999999. 500000-999999 means you WIN!

Details:
To generate the provably fair number, get the blockhash of the block that includes your transaction, concatenate with the next 3 block's blockhash concatenate with your txid
Take the string generated and hash it with SHA-256.
Take the first 5 digits of the SHA-256 and convert to decimal from base 16 Hexidecimal. If this number is less than 1,000,000 then this is the generated number. If not, take the next 5 and so on until the generated number under 1 million.

Provably Fair:
Because no one can predict the next blockhash without 50% of the mining power, it is safe that its generated randomly
In order to cheat, one must mine the block that includes the gambling transaction and the next 3 block before broadcasting the gambling transaction. This is impossible to do.
*/
//Copy paste the commented line below into the console with your transaction id that you want to roll
//getBlockInfo('5bc79366fc8e21105ad022c09e9a79834172eea3bf75d4a63750bc43d43faad0');
let main = 'https://api.blockcypher.com/v1/btc/main';
function getBlockInfo(txid){
  fetch(main + '/txs/' + txid).then((txdata) => txdata.json()).then(function(data){
    fetch(main + '/blocks/' + (parseInt(data.block_height) + 1) + '?txstart=1&limit=1').then((txdata2) => txdata2.json()).then(function(data2){
      fetch(main + '/blocks/' + (parseInt(data.block_height) + 2) + '?txstart=1&limit=1').then((txdata3) => txdata3.json()).then(function(data3){
        setTimeout(function (){ //To stop API limits
          fetch(main + '/blocks/' + (parseInt(data.block_height) + 3) + '?txstart=1&limit=1').then((txdata4) => txdata4.json()).then(function(data4){
            provableRandomNum(data.block_hash + data2.hash + data3.hash + data4.hash, txid);
          });
        }, 1000);
      });
    });
  });
}

async function sha256(message) {
  const msgBuffer = new TextEncoder('utf-8').encode(message);
  const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
  const hashArray = Array.from(new Uint8Array(hashBuffer));
  const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
  return hashHex;
}

async function provableRandomNum(blockhash, txid) {
  sha256(blockhash + txid).then(function(res) {
    for (let i = 0; i < 64 / 5; i++) {
      //transform hash into blocks of 5 and convert it to int from hex
      let result = parseInt(res.substring(i * 5, 5), 16);
      if (result < 1000000){
          console.log(result);
          return;
      }
    }
  });
}

              
            
!
999px
If a groundhog inspects their Web Component, do they see their Shadow DOM?

Console