Page cover

🧷On-Chain Encryption

On-chain encryption utilizes blockchain technology to record and verify the transmission and storage process of messages, ensuring data immutability and transparency.

  • Blockchain Recording: The hash value and metadata (such as timestamp, sender, and receiver identity) of each message are recorded on the blockchain, forming an immutable log.

  • Smart Contracts: Smart contracts manage and verify the data transmission process, ensuring data integrity and authenticity.

// Example: On-Chain Records

import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');

const contractAddress = '0xYourContractAddress';

const abi = [

// contract ABI

];

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

// Storing Message Hashes

async function storeMessageHash(hash) {

const signer = provider.getSigner();

const tx = await contract.connect(signer).storeMessageHash(hash);

await tx.wait();

console.log('Message hash stored on blockchain');

}