Smart Contract Communication Flow
User Action:
The user initiates a transaction, such as paying for access or claiming a reward.
The frontend application communicates with the backend to process the transaction.
Blockchain Processing:
The transaction is submitted to the TON blockchain.
Smart contracts execute the defined logic upon confirming the transaction.
Event Emission:
Smart contracts emit relevant events, such as
AccessGranted
,RewardDistributed
, etc.These events include essential details, such as user addresses, transaction amounts, and timestamps.
Backend Listener:
The backend server monitors these events using TON’s APIs and SDKs.
Upon detecting an event, the backend verifies the transaction details for accuracy.
Database Update:
The backend updates the platform’s database to reflect the new state (e.g., access granted, rewards added).
It ensures consistency between the on-chain data and the platform's internal state.
User Notification:
The platform notifies the user of the completed action (e.g., access granted, reward received).
Notifications are sent via in-app messages, emails, or push notifications, depending on user preferences.
Essential Smart Contract Functions
1. Contact Request Payment Processing (contactRequest
)
contactRequest
)Input:
recipientAddress
: The TON blockchain address of the recipient.
Process:
Validate that the payment amount matches the recipient’s fee.
Transfer the payment from the sender to the recipient, deducting a platform fee.
Emit an event with transaction details, including the sender, recipient, amount, and platform fee deducted.
2. Token Rewards for Adherence to Platform Rules ( rewardCompliance )
rewardCompliance )
Inputs:
userAddress
: The TON blockchain address of the user to reward.complianceType
: A code or identifier representing the type of rule adhered to (e.g.,timelyResponse
,positiveFeedback
).metadataHash
: A hash of the compliance data stored off-chain for verification purposes.
Process:
Verify that the function is called by an authorized platform address, such as the backend service.
Validate the compliance against off-chain data to confirm adherence to the specified rule. This may involve verifying digital signatures or proofs generated by the backend.
Determine the reward amount based on the
complianceType
.Distribute the reward to the user’s address.
Transfer the calculated $KURO amount from the platform's reward pool to the
userAddress
. Update the platform's internal accounting to reflect the distribution.
3. Staking Rewards Distribution (distributeStakingRewards
)
distributeStakingRewards
)Inputs:
userAddress
: The TON blockchain address of the user who staked tokens.stakeAmount
: The amount of tokens the user has staked.stakingDuration
: The duration (in blocks) for which the tokens have been staked.rewardRate
: The annualized rate of return for staking (expressed as a percentage).
Process:
Ensure that the function call is made by an authorized contract or staking manager.
Validate that the user has an active stake recorded in the contract.
Calculate the reward based on the
stakeAmount
,stakingDuration
, andrewardRate
.Ensure that there are sufficient funds in the rewards pool to cover the calculated reward.
Transfer the calculated reward amount from the contract’s rewards pool to the user.
Update the contract’s internal accounting to reflect the distribution and adjust the user's stake status if necessary.
4. Token Transfer Function (transferTokens
)
transferTokens
)Inputs:
senderAddress
: The TON blockchain address of the user initiating the transfer.recipientAddress
: The TON blockchain address of the user receiving the tokens.amount
: The amount of tokens to transfer.
Process:
Ensure that the function call is made by the
senderAddress
.Validate that the
amount
to transfer is greater than zero.Transfer the specified
amount
from the sender to the recipient.Emit an event confirming the transaction details (e.g., sender, recipient, amount).
Last updated