SampleContractHook

A sample Solidity Smart Contract to show how to code your own Contract Hook. Contract Hooks are called every time a user with it setup gets tagged in a message.

Table of Contents


Admin Functions

pause

The pause function is used to halt all the activities of the contract. Only an admin can pause the contract.

Input

This function does not require any input parameters.

Output

This function does not return any output.

Example Usage

const ethers = require('ethers');

// Initialize ethers with provider and signer
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
const signer = provider.getSigner();

// Set contract address and ABI
const contractAddress = "contract address goes here";
const contractABI = "contract ABI goes here";

// Create contract instance
const contractInstance = new ethers.Contract(contractAddress, contractABI, signer);

// Call pause function
await contractInstance.pause();

unpause

The unpause function is used to resume the activities of the contract after being paused by an admin.

Input

This function does not require any input parameters.

Output

This function does not return any output.

Example Usage

// Call unpause function
await contractInstance.unpause();

updateAdmin

The updateAdmin function allows an admin to add or remove other admins.

Input

Variable
Type
Description

admin

address

Address of the admin to be updated

status

bool

True to add, false to remove

Output

This function does not return any output.

Example Usage

const newAdmin = "0xNewAdminAddressHere";
const status = true;

// Update admin status
await contractInstance.updateAdmin(newAdmin, status);

updateKUTHULUContracts

The updateKUTHULUContracts function allows an admin to set the KUTHULU contracts.

Input

Variable
Type
Description

contractAddress

address

Address of the contract to be updated

status

bool

True to add, false to remove

Output

This function does not return any output.

Example Usage

const contractAddress = "0xContractAddressHere";
const status = true;

// Update KUTHULU contract status
await contractInstance.updateKUTHULUContracts(contractAddress, status);

updateContracts

The updateContracts function allows an admin to update the addresses of KUTHULU, KUtils and DOOM contracts.

Input

Variable
Type
Description

_kuthulu

address

New address of the KUTHULU contract

_kutils

address

New address of the KUtils contract

_doom

address

New address of the DOOM contract

Output

This function does not return any output.

Example Usage

const newKuthulu = "0xNewKuthuluAddressHere";
const newKutils = "0xNewKutilsAddressHere";
const newDoom = "0xNewDoomAddressHere";

// Update contract addresses
await contractInstance.updateContracts(newKuthulu, newKutils, newDoom);

mintDoom

The mintDoom function allows an admin to mint a certain quantity of DOOM tokens to the contract for it to spend on posting back to KUTHULU.

Input

Variable
Type
Description

quantity

uint256

Amount of DOOM tokens to be minted

Output

This function does not return any output.

Example Usage

const quantity = ethers.utils.parseEther("10");

// Mint DOOM tokens
await contractInstance.mintDoom(quantity);

KUTHULU Functions

KuthuluHook

The KuthuluHook function serves as a means of receiving a message and logging its details for testing purposes. It's set to skip al functionality and just return true if a msgID of 0 is sent. This is done when the user sets up the Contract Hook on KUTHULU and KUTHULU calls this contract to verify that it's setup correctly. Once a non-zero message ID is received when a regular post is sent via the KUTHULU Contract Hook, the function posts a test message acknowledging the receipt of the original message by calling the postMessage private function.

Parameters

Parameter
Type
Description

newMsg

MsgData (memory)

An object holding all relevant details of a message.

The MsgData object contains the following fields:

Field
Type
Description

msgID

uint

ID of the message.

postedBy

address[2]

Addresses of the message poster and the proxy.

message

string

Content of the message.

paid

bool

Indicator if the message is paid.

hashtags

string[]

Array of hashtags included in the message.

taggedAccounts

address[]

Array of accounts tagged in the message.

asGroup

uint

ID of the group where the message was posted.

inGroups

uint[]

Array of group IDs where the message was posted.

uri

string

URI of the message.

commentLevel

uint

The comment level of the message.

isCommentOf

uint

Message ID that the current message is a comment of.

isRepostOf

uint

Message ID that the current message is a repost of.

msgStats

MsgStats (object)

An object holding statistics about the message.

The MsgStats object within the MsgData object has the following fields:

Field
Type
Description

postByContract

bool

Indicator if the message was posted by a contract.

time

uint

Timestamp when the message was posted.

block

uint

Block number when the message was posted.

tipsReceived

uint

Total tips received to split among all tagged accounts.

tipERC20Amount

uint

Total amount of ERC20 token tips received.

Returns

Parameter
Type
Description

bool

Returns a boolean value (True) if the function execution is successful.

Should it return false, then no one will be able to tag the user or group with the contract hook in place as the transaction will always revert.

Usage with ethers.js

const contract = new ethers.Contract(contractAddress, abi, provider);

const newMsg = {
  msgID: 1,
  postedBy: ['0x...', '0x...'],
  message: 'Hello, world!',
  paid: true,
  hashtags: ['#test'],
  taggedAccounts: ['0x...'],
  asGroup: 123,
  inGroups: [123, 456],
  uri: 'https://example.com/message/1',
  commentLevel: 1,
  isCommentOf: 0,
  isRepostOf: 0,
  msgStats: {
    postByContract: false,
    time: Math.floor(Date.now() / 1000),
    block: 123456,
    tipsReceived: 10,
    tipERC20Amount: 20
  }
};

async function executeFunction() {
  const tx = await contract.KuthuluHook(newMsg);
  console.log(tx);
}

executeFunction();

Public Functions

getKuthuluMsgCount

The getKuthuluMsgCount function fetches the total number of messages posted in KUTHULU. It can be used to track the activities on the KUTHULU platform.

Input

This function does not require any input parameters.

Output

Variable
Type
Description

output

uint256

Total number of messages in the KUTHULU app

Example Usage

// Fetch total message count
const messageCount = await contractInstance.getKuthuluMsgCount();

postTestMessage

This function is marked as private in the contract. Therefore, it cannot be accessed or called directly from outside the contract.

This function is triggered internally by the KuthuluHook function which is called by KUTHULU when the contract hook is invoked.

The postTestMessage function posts a test message back to KUTHULU, and is used for testing purposes within the contract.


toggleLike

This function is marked as private in the contract. Therefore, it cannot be accessed or called directly from outside the contract.

The toggleLike function allows a user to toggle this contracts like status for a particular message on the KUTHULU platform.

Last updated