LTO Network
  • Getting started
  • What is LTO Network?
  • Tutorials
    • Buying and staking LTO
      • Exchanges
        • Binance
        • AscendEX (Bitmax)
        • Uniswap
        • PancakeSwap
        • Other exchanges
      • Creating your LTO web wallet
      • Using the LTO token bridge
      • Staking LTO tokens
    • Mining
      • Setup your node wallets
      • Node management
      • Public community nodes
    • Anchoring
      • Hashing
    • LetsFlow
  • Wallets
    • LTO Web Wallet
      • Using Ledger
    • Universal Wallet
    • LTO CLI
    • Third-Party Wallets
      • Stakely.io wallet
        • Web wallet
        • Commandline
    • ERC20 Token Swap
  • Running a node
    • Public node
      • Installation Guide
        • Mainnet & Testnet
        • Requirements
        • Configuration
        • (Virtual) Machine
        • Nginx reverse proxy (optional)
        • Troubleshooting FAQ
      • Cloud installation
        • Alibaba Cloud
        • AWS Elastic Beanstalk
        • Google Cloud
        • IBM Cloud
        • Microsoft Azure
        • OKD (OpenShift)
        • Raspberry Pi (Expert)
        • Ubuntu Linux with Container
        • Windows with Container
      • REST API
        • Address
        • Wallet
        • Lease Transactions
        • Peers
        • Blocks
        • Utils
        • FAQ
      • Security Notes
      • FAQ
      • Exchange integration guide
    • Anchor node
      • Installation Guide
        • Linux
        • MacOS
        • Windows
      • REST API
    • Identity node
      • Installation guide
        • Linux
        • MacOs
        • Windows
      • Configuration
        • Trust network
      • REST API
    • Workflow node
      • Installation Guide
        • MacOS
        • Windows
        • Ubuntu Linux
      • REST API
  • Ownables
    • What are Ownables?
    • Making your first ownable
    • Ownables SDK
      • Prerequisites
      • Setup
    • Ownables Architecture
      • Smart Contract
      • Widget
    • Ownables Bridge
  • Templates Overview
  • Libraries
    • JavaScript
      • Accounts
      • Transactions
      • Event chain
      • Messages
      • Identities
      • HTTP Authentication
    • Python
      • Accounts
      • Public layer
    • PHP
      • Accounts
      • Identities
      • Public layer
      • Private layer
      • HTTP Authentication
      • Commandline scripts
    • Java
  • Protocol
    • Cryptography
    • Accounts
      • ED25519
      • secp256k1
      • secp256r1
    • Identities
      • Decentralized identifiers (DID)
      • Trust network
      • Verifiable credentials
    • Public layer
      • Transactions
        • Transfer
        • Lease
        • Cancel Lease
        • Mass Transfer
        • Set Script
        • Data
        • Anchor
        • Association
        • Revoke Association
        • Sponsorship
        • Cancel Sponsorship
        • Register
        • Burn
        • Mapped Anchor
        • Statement
      • Transaction fees
      • Consensus protocol
      • Activation Protocol
      • Data Structures
    • Private layer
      • Event chain
        • Event
      • Messaging
        • Sending messages
Powered by GitBook
On this page
  • HTML
  • Styling
  • Javascript
  1. Ownables
  2. Ownables Architecture

Widget

The other side of the Ownable package will contain the visual elements: HTML, and media files like images and videos.

HTML

The index.html file will be rendered as widget in the wallet. It should have a structure resembling the following:

<html>
  <head>
    <style>
      // all the styles for your ownable
    </style>
  </head>
  <body>
    <div>
      // your ownable html
    </div>
    <script>
      // any necessary functions
    </script>
  </body>

Styling

The styling should be responsive on all devices. As the wallet will render your provided template, you are in complete control of how it will be displayed.

.square {
  width: 50vw;
  height: 50vh;
  border: 1px solid black;
}

img.banner {
  width: 80vw;
  aspect-ratio: 4:1;
}

Javascript

Ownable templates communicate with the wallet via messages.

An execute message can be sent to the window parent, which will be forwarded to the CosmWasm smart contract and stored on the event chain.

window.parent.postMessage({
  type: "execute",
  ownable_id: ownable_id,
  msg: {
    "do_something: {}
  }
});

The widget will receive a message from the parent window after the state of the smart contract changes.

window.addEventListener("message", (event) => {
  const state = event.data.state;
  document.getElementById("my_element").style.backgroundColor = state.color;
});

Example

If we consider the potion example which you can find in our demo repository, the script part of our HTML template may contain methods like this:

// Listen for a click on the button defined in the html template
// which will trigger the consume method
document.getElementById("drink-button").addEventListener('click', () => consume());

function consume() {
  // building the message to be passed to WASM for execution
  // this should match the msg expected by the lib.rs entry points
  let msg = {
    "consume": {
      "amount": getDrinkAmount(),
    },
  };
  // posting the message to the wallet which will relay it to WASM
  // check index.js for the listener to see how it does it
  // https://github.com/ltonetwork/ownable-demo/blob/eb0bda9c323659a78d69bd669861f46473d16fa2/www/index.js#L163
  window.parent.postMessage({type: "execute", ownable_id, msg}, "*");
}

// gets the selected amount to drink from the html slider
function getDrinkAmount() {
  let stringAmount = document.getElementsByClassName('slider')[0].valueOf().value;
  return parseInt(stringAmount);
}

// listener for the wallet messages indicating the state after the execute msg
// see wasm-wrappers.js for details:
// https://github.com/ltonetwork/ownable-demo/blob/main/www/wasm-wrappers.js#L210-L217
window.addEventListener("message", (event) => {
  const state = event.data.state;
  updateTemplate(state.color, state.current_amount)
});

// method to update the visual template defined in the html file
function updateTemplate(color, amt) {
  document.getElementsByClassName('juice')[0].style.backgroundColor = color;
  document.getElementsByClassName('juice')[0].style.top = (100 - amt) + '%';
  document.getElementsByClassName('juice')[0].style.height = amt + '%';
  document.getElementsByClassName('amount')[0].textContent = amt;
}
PreviousSmart ContractNextOwnables Bridge

Last updated 2 years ago

The widgets in which the Ownables will be placed always have a 1:1 aspect ratio (square). Use the vh and vw, and/or to ensure the content of the widget properly scales.

viewport units
aspect-ratio