How to Use ChainNet Functions
Last updated
Last updated
ChainNet offers a groundbreaking approach to hosting websites directly on-chain through a set of smart contract functions: setWebPageHTML
, setWebPageCSS
, setWebPageJS
, and setWebPageURL
. These functions provide developers with the flexibility to store, update, and retrieve their web content in a decentralized manner. This guide will dive deep into how these functions work, why they are essential, and how to utilize them effectively for on-chain website hosting.
setWebPageURL
WorksThe setWebPageURL
function allows you to override the on-chain HTML, CSS, and JS with a direct link to an external website. When this function is set to a non-empty URL, ChainNet will load the page from that URL, bypassing the on-chain content.
You may want to link to a dynamic or larger website that is impractical to store on-chain due to gas costs.
If you want to utilize on-chain content instead, ensure that getWebPageURL
returns an empty string (""
). This will trigger the browser to load the HTML, CSS, and JS stored within the smart contract.
setWebPageHTML
, setWebPageCSS
, and setWebPageJS
These functions allow you to store the core components of your webpage directly on-chain. This content can be accessed, modified, and rendered directly by ChainNet.
Stores the structure of your webpage. This can include elements like <div>
, <p>
, <img>
, and more.
Defines the styling of your webpage. It is automatically inserted into the <head>
section of your HTML.
Contains the JavaScript necessary for interactive elements on your page.
Storing and Retrieving HTML The setWebPageHTML function lets you store your webpage's HTML content directly on-chain. This is where you define the structure and content of your webpage.
Here’s how you might structure a simple "Hello World"
page:
CSS: This is where you define the visual appearance of your webpage. The CSS you store on-chain using setWebPageCSS is directly injected into the <head>
section of your HTML.
JS: This function stores JavaScript code, enabling interactive elements on your webpage. It's crucial for dynamic content, form validations, animations, etc.
The setWebPageHTML
, setWebPageCSS
, setWebPageJS
, and setWebPageURL
functions empower developers to fully utilize the blockchain for decentralized web hosting. Whether you want to host an entire site directly on-chain or simply link to an off-chain resource, ChainNet's robust set of functions makes it possible.
By embracing these tools, you not only ensure that your content is secure and censorship-resistant but also contribute to the growing ecosystem of decentralized, blockchain-based web technologies.