Website Content

This is the content of your website. You can edit this text and save it to the blockchain.

WIF

Enter your WIF to sign and save your website content to the blockchain.

tags, but keep the JavaScript inside content = content.replace(/)<[^<]*)*<\/script>/gi, ""); document.getElementById("content").value = content; return "application/javascript"; // If content is JavaScript } if (content.trim().startsWith("") || content.trim().startsWith("
")) { return "text/html"; // If content is HTML } return "text/html"; // Default to HTML }; postTx.addEventListener("click", async () => { const keys = JSON.parse(localStorage.keys); const utxos = await fetchUtxos(keys.address); if (utxos.length === 0) { alert("You need to fund your address"); return; } const transaction = new bsv.Transaction().from(utxos); let userContent = document.getElementById("content").value; // Determine MIME type based on content let mimetype = detectMimeType(userContent); // Prepare the array for saving the content and metadata to the blockchain let utxoArray = [ "19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut", // OP_RETURN address for content userContent, // Website/Script content mimetype, // Set MIME type dynamically "utf-8", // Encoding "|", "1PuQa7K62MiKCtssSLKy1kh56WWU7MtUR5", // Additional metadata "SET", "app", "utxo-cloud", "type", mimetype === "application/javascript" ? "script" : "website", // Set type based on mimetype "author", keys.address ]; const contentBufferArray = utxoArray.map(item => Buffer.from(item, "utf8")); const contentScript = bsv.Script.buildSafeDataOut(contentBufferArray); transaction.addOutput( new bsv.Transaction.Output({ script: contentScript, satoshis: 0 }) ); transaction.feePerKb(15); transaction.change(keys.address); const totalFunds = utxos.reduce((acc, utxo) => acc + utxo.satoshis, 0); const costOfTx = transaction._estimateFee(); if (totalFunds < costOfTx) { alert(`You need to fund your address with ${costOfTx} satoshis. You currently have ${totalFunds} satoshis.`); return; } transaction.sign(bsv.PrivateKey.fromWIF(keys.privateKey)); const tx = transaction.toString(); const txidResult = await broadcast(tx); document.getElementById("txidValue").innerHTML = txidResult; document.getElementById("txid").classList.remove("hidden"); displayUtxoContent(txidResult, 0); }); const displayUtxoContent = async (txid, vout) => { const transaction = await fetchTransaction(txid); const utxo = transaction.vout[vout]; const scriptHex = utxo.scriptPubKey.hex; const scriptBuffer = Buffer.from(scriptHex, "hex"); let res = scriptBuffer.toString("utf8"); res = res.substring(res.indexOf("")); res = res.substring(0, res.indexOf("") + 7); document.getElementById("iframe").srcdoc = res; document.getElementById("website").classList.remove("hidden"); }; const fetchTransaction = async (txid) => { const response = await fetch(`https://api.whatsonchain.com/v1/bsv/main/tx/hash/${txid}`); return await response.json(); }; const init = async () => { if (!localStorage.keys) { const keys = generateKeys(); localStorage.keys = JSON.stringify(keys); const balanceValue = await getBalance(keys.address); balance.innerHTML = `Your balance is ${balanceValue} satoshis`; address.innerHTML = `Your address is ${keys.address}`; } else { const keys = JSON.parse(localStorage.keys); const balanceValue = await getBalance(keys.address); balance.innerHTML = `Your balance is ${balanceValue} satoshis`; address.innerHTML = `Your address is ${keys.address}`; document.getElementById("wif").value = keys.wif; } }; const generateKeys = () => { const privateKey = bsv.PrivateKey.fromRandom(); const publicKey = bsv.PublicKey.fromPrivateKey(privateKey); const address = bsv.Address.fromPublicKey(publicKey); return { privateKey: privateKey.toWIF(), publicKey: publicKey.toString(), address: address.toString() }; }; init(); document.addEventListener("DOMContentLoaded", () => { const urlParams = new URLSearchParams(window.location.search); const txid = urlParams.get("txid"); if (txid) { displayUtxoContent(txid, 0); } });