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.

Behavior

Save Automatically?

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.

HTML

              
                <h4>In this demo, it helps you to understand how to request user to login and enforce address to buy an item</h4>

<pre id="loggedIn">Please login</pre>

<button id="loginBtn" onclick="login()">Login</button>

<button id="logoutBtn" onclick="logout()">Logout</button>

<br><br>

<div id="item" style="display: none;">

  <fieldset style="width:40%">
    <legend>Item #1</legend>
    <img src="https://png.pngtree.com/element_our/png/20180930/artificial--brain--intelligence-png_116457.jpg" width=100px height=100px></img>
    <br><br>
    <label>Skill stats: connex skill +2: <br>It helps you to understand how to get the user address and enforced(designated) the address to proceed purchase</label><br><br>
    <input onclick="buy()" type="submit" value="Buy">
  </fieldset>
  <br><br>

  <pre id="txidLabel"></pre>
  <caption>brain icons PNG Designed By syedhassan from <a href="https://pngtree.com"> Pngtree.com</a></caption>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                const vendor = new Connex.Vendor("test");
var addressLabel = document.getElementById("loggedIn");
var address = "";

var itemDiv = document.getElementById("item");

function login() {
  vendor
    .sign("cert", {
      purpose: "identification",
      payload: {
        type: "text",
        content: "Please sign the certificate to continue purchase"
      }
    })
    // .accepted(() => alert("accepted"))
    .request()
    .then((r) => {
      address = r.annex.signer;
      addressLabel.innerText = "Logged In: " + address;
      itemDiv.style.display = "inline-block";
    })
    .catch((e) => console.log("error:" + e.message));
}

function logout() {
  addressLabel.innerText = "Please login";
  itemDiv.style.display = "none";
  address = "";
}

function buy() {
  var txIdLabel = document.getElementById("txidLabel");
  vendor
    .sign("tx", [
      {
        to: "0x70aE85A2fF6030366F512DbcD60Be3828139b498",
        value: 1 * 1e18, //unit in wei
        data: "0x"
      }
    ])
  //enforce signer
  .signer(address)
    //a link that can redirect user to visit
    .link("https://explore-testnet.vechain.org/transactions/{txid}")
    .comment("buy skill stats: connex skill +2")
    // .accepted(() => alert("accepted"))
    .request()
    .then((r) => (txIdLabel.innerText = "TxId: " + r.txid))
    .catch((e) => console.log("error:" + e.message));
}

              
            
!
999px

Console