SC CODE: // Copyright 2024. Civilware. All rights reserved.
// TELA Decentralized Web Document (TELA-DOC-1)
Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "mm.js")
31 STORE("descrHdr", "MetaMask")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "mm.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "1d5dbb9eecf5607f71087d5e2035a44b60a0b73d60a833d116dc98b48ff6c179")
37 STORE("fileCheckS", "585ec33bfdf2b868bd14104b1568f868197fa2a828cfca69150c55a490526c6")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*const use_chain_id = 369;
const messages = document.querySelector('.messages');
// Account and connection stuff
const ethereumButton = document.querySelector('.enableEthereumButton');
const showAccount = document.querySelector('.showAccount');
const showChainId = document.querySelector('.showChainId');
var web3;
var connected_evm_account='';
// check if web3 is available
if (typeof window.ethereum !== 'undefined') {
// use the browser injected Ethereum provider
web3 = new Web3(window.ethereum);
setChainId();
registerHandlers();
web3.eth.transactionPollingTimeout = 1000;
} else {
// if window.ethereum is not available, give instructions to install MetaMask
messages.innerHTML =
'Please install MetaMask to connect';
}
ethereumButton.addEventListener('click', async () => {
setChainId();
connectToMetaMask();
});
async function connectToMetaMask(){
handleConnectButton("Waiting");
let error = await requestAccounts();
if(error === ''){
messages.innerHTML = "";
getAccount();
}else{
if (error.code === 4001) {
handleConnectButton("Connect");
messages.innerHTML = "Please connect to MetaMask.";
}else if(error.code === -32002){
messages.innerHTML = "Waiting for sign-in.";
}
}
}
async function requestAccounts() {
let error ='';
await window.ethereum.request({ method: 'eth_requestAccounts' })
.catch((err) => {
error = err;
});
return error;
}
async function getAccount() {
handleConnectButton("Connect");
// get list of accounts
const accounts = await web3.eth.getAccounts();
if(accounts.length > 0){
// show the first account
connected_evm_account = accounts[0];
showAccount.innerHTML = connected_evm_account;
handleConnectButton();
}
}
var chain_selected = 0;
function displayChainInfo(chainId){
chain_selected = web3.utils.hexToNumberString(chainId);
let chains = [];
chains[369] = 'pls';
chains[943] = 'plsV4testnet';
chains[1] = 'eth';
showChainId.innerHTML = chain_selected + "-"+ chains[chain_selected];
}
async function setChainId(){
var chainId = await window.ethereum.request({ method: 'eth_chainId' });
displayChainInfo(chainId);
}
function handleConnectButton(text=""){
if(text != ""){
ethereumButton.innerHTML = text;
}else if(window.ethereum.isConnected()){
ethereumButton.innerHTML = "Connected";
ethereumButton.style.color = "green";
CStatusChange();
}else{
ethereumButton.innerHTML = "Connect";
CStatusChange();
}
}
function registerHandlers(){
window.ethereum.on('chainChanged', displayChainInfo);
window.ethereum.on("accountsChanged", getAccount);
window.ethereum.on("disconnect", handleConnectButton);
}
//Check / update this before deployment
async function connectionOK(){
if(chain_selected == use_chain_id && connected_evm_account != ""){
return true;
}
await alertModal("MetaMask Wallet connection required. Make sure you are connected to PulseChain (chain id 369)");
return false;
}
const HTLContractABI = [
{
"inputs": [
{
"internalType": "address",
"name": "_receiver_address",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "deadline",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "deposited",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "hash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "key",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "receiver",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "refund",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_hash",
"type": "bytes32"
}
],
"name": "startSwap",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_key",
"type": "string"
}
],
"name": "withdraw",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "payable",
"type": "function"
}
];
function getInstallByteCode(days){
let insert_1;
let insert_2;
if (days === 1){
return pls1daycontract;
}else if(days === 2){
return pls2daycontract;
}else{
return false;
}
}
*/ |
SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'// Copyright 2024. Civilware. All rights reserved.
// TELA Decentralized Web Document (TELA-DOC-1)
Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "mm.js")
31 STORE("descrHdr", "MetaMask")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "mm.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "1d5dbb9eecf5607f71087d5e2035a44b60a0b73d60a833d116dc98b48ff6c179")
37 STORE("fileCheckS", "585ec33bfdf2b868bd14104b1568f868197fa2a828cfca69150c55a490526c6")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*const use_chain_id = 369;
const messages = document.querySelector('.messages');
// Account and connection stuff
const ethereumButton = document.querySelector('.enableEthereumButton');
const showAccount = document.querySelector('.showAccount');
const showChainId = document.querySelector('.showChainId');
var web3;
var connected_evm_account='';
// check if web3 is available
if (typeof window.ethereum !== 'undefined') {
// use the browser injected Ethereum provider
web3 = new Web3(window.ethereum);
setChainId();
registerHandlers();
web3.eth.transactionPollingTimeout = 1000;
} else {
// if window.ethereum is not available, give instructions to install MetaMask
messages.innerHTML =
'Please install MetaMask to connect';
}
ethereumButton.addEventListener('click', async () => {
setChainId();
connectToMetaMask();
});
async function connectToMetaMask(){
handleConnectButton("Waiting");
let error = await requestAccounts();
if(error === ''){
messages.innerHTML = "";
getAccount();
}else{
if (error.code === 4001) {
handleConnectButton("Connect");
messages.innerHTML = "Please connect to MetaMask.";
}else if(error.code === -32002){
messages.innerHTML = "Waiting for sign-in.";
}
}
}
async function requestAccounts() {
let error ='';
await window.ethereum.request({ method: 'eth_requestAccounts' })
.catch((err) => {
error = err;
});
return error;
}
async function getAccount() {
handleConnectButton("Connect");
// get list of accounts
const accounts = await web3.eth.getAccounts();
if(accounts.length > 0){
// show the first account
connected_evm_account = accounts[0];
showAccount.innerHTML = connected_evm_account;
handleConnectButton();
}
}
var chain_selected = 0;
function displayChainInfo(chainId){
chain_selected = web3.utils.hexToNumberString(chainId);
let chains = [];
chains[369] = 'pls';
chains[943] = 'plsV4testnet';
chains[1] = 'eth';
showChainId.innerHTML = chain_selected + "-"+ chains[chain_selected];
}
async function setChainId(){
var chainId = await window.ethereum.request({ method: 'eth_chainId' });
displayChainInfo(chainId);
}
function handleConnectButton(text=""){
if(text != ""){
ethereumButton.innerHTML = text;
}else if(window.ethereum.isConnected()){
ethereumButton.innerHTML = "Connected";
ethereumButton.style.color = "green";
CStatusChange();
}else{
ethereumButton.innerHTML = "Connect";
CStatusChange();
}
}
function registerHandlers(){
window.ethereum.on('chainChanged', displayChainInfo);
window.ethereum.on("accountsChanged", getAccount);
window.ethereum.on("disconnect", handleConnectButton);
}
//Check / update this before deployment
async function connectionOK(){
if(chain_selected == use_chain_id && connected_evm_account != ""){
return true;
}
await alertModal("MetaMask Wallet connection required. Make sure you are connected to PulseChain (chain id 369)");
return false;
}
const HTLContractABI = [
{
"inputs": [
{
"internalType": "address",
"name": "_receiver_address",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "deadline",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "deposited",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "hash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "key",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "receiver",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "refund",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_hash",
"type": "bytes32"
}
],
"name": "startSwap",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_key",
"type": "string"
}
],
"name": "withdraw",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "payable",
"type": "function"
}
];
function getInstallByteCode(days){
let insert_1;
let insert_2;
if (days === 1){
return pls1daycontract;
}else if(days === 2){
return pls2daycontract;
}else{
return false;
}
}
*/'] |