Emit
Solidityपरिभाषा
Emit keyword का use events को trigger करने के लिए होता है। Events blockchain के transaction logs में store होते हैं और off-chain applications (frontends, indexers) इन्हें listen कर सकते हैं। Events smart contract से data retrieve करने का एक gas-efficient तरीका है।
English version
The emit keyword is used to trigger events. Events are stored in the blockchain's transaction logs and can be listened to by off-chain applications (frontends, indexers). Events are a gas-efficient way to retrieve data from smart contracts.
Code Example
event Transfer(address indexed from, address indexed to, uint256 amount);
function transfer(address to, uint256 amount) public {
balances[msg.sender] -= amount;
balances[to] += amount;
emit Transfer(msg.sender, to, amount);
}
// Écouter l'événement (JavaScript)
contract.on("Transfer", (from, to, amount) => {
console.log(`Transfer: ${from} → ${to}: ${amount}`);
});संबंधित पेज
Solingo पर इस concept को practice करें
Emit को interactive exercises और integrated IDE के साथ master करें।
मुफ्त में शुरू करें