0Pricing
Web3 & DApp Development Fundamentals · 강의

이벤트 선언하기

온체인 로그 내보내기

이벤트 선언하기은(는) CoddyKit의 무료 Web3 & DApp Development Fundamentals 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Web3 & DApp Development Fundamentals 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Web3 & DApp Development Fundamentals 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What Are Events?

Events let a smart contract write entries to the blockchain's log. These logs are a cheap way to record that something happened and are the primary channel for contracts to communicate with off-chain applications.

Front-ends, indexers, and analytics tools all listen for events.

Declaring an Event

You declare an event with the event keyword and a list of typed parameters. The declaration defines the event's shape.

<code>event Transfer(address from, address to, uint256 amount);</code>

Emitting an Event

To fire an event you use the emit keyword followed by the event name and arguments. This appends a log entry to the transaction receipt.

<code>function send(address to, uint256 amount) public {
    // ... transfer logic
    emit Transfer(msg.sender, to, amount);
}</code>

Why Use Events?

Events solve two problems:

  • Cheap record-keeping - logs cost far less gas than storage
  • Off-chain communication - dApps cannot read storage in real time, but they can subscribe to events

Contracts themselves cannot read their own emitted events, however.

A Complete Example

Here is a small contract that emits an event whenever a value is updated, so any listening app knows the change immediately.

<code>contract Counter {
    uint256 public count;
    event Incremented(uint256 newCount);

    function increment() public {
        count += 1;
        emit Incremented(count);
    }
}</code>

Logs Are Not Storage

Event data is stored in a special log area of the transaction receipt, not in contract storage. This is why they are cheap, but it also means the contract cannot query past events on-chain.

Logs are accessible to off-chain clients and block explorers.

Naming and Conventions

By convention events are named with PascalCase and often describe a past action: Transfer, Approval, Deposit, OwnershipTransferred.

Standard interfaces like ERC-20 define required events you must emit.

<code>event Approval(address owner, address spender, uint256 value);
event Deposit(address account, uint256 amount);</code>

Multiple Parameters

Events can carry several parameters of any type, including string and bytes. The data is ABI-encoded into the log.

<code>event OrderPlaced(uint256 id, address buyer, string product, uint256 price);

function place(uint256 id, string memory p, uint256 price) public {
    emit OrderPlaced(id, msg.sender, p, price);
}</code>

Gas Cost of Events

Emitting an event costs gas, but much less than writing the same data to storage. The base cost plus a small per-byte fee makes events the preferred way to expose historical data.

Rule of thumb: store what the contract needs to read, emit what off-chain apps need to read.

Events in the ABI

Event declarations appear in the contract's ABI so that client libraries know how to decode the logs. The event signature is hashed to create a topic identifier.

<code>// ABI entry (simplified)
// { type: 'event', name: 'Transfer',
//   inputs: [from, to, amount] }</code>

Events for State Changes

A best practice is to emit an event for every meaningful state change. This gives applications a reliable, ordered history they can replay to rebuild state.

<code>address public owner;
event OwnerChanged(address previous, address next);

function setOwner(address next) public {
    emit OwnerChanged(owner, next);
    owner = next;
}</code>

Quick Check

Test your understanding of declaring events.

Recap

You learned how to declare and emit events:

  • Declare with event Name(types...)
  • Fire with emit Name(args...)
  • Logs are cheap, off-chain readable, and not queryable on-chain
  • Emit an event for every meaningful state change

Events are the bridge between your contract and the outside world.

자주 묻는 질문

“이벤트 선언하기” 강의는 무료인가요?

네 — “이벤트 선언하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Web3 & DApp Development Fundamentals 강의 전체를 잠금 해제할 수 있습니다. Web3 & DApp Development Fundamentals 강의에는 총 4개의 강의가 포함되어 있습니다.

“이벤트 선언하기”에서 뭘 배우나요?

온체인 로그 내보내기 브라우저에서 직접 실행하는 실습 코드로 Web3 & DApp Development Fundamentals을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Web3 & DApp Development Fundamentals을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Web3 & DApp Development Fundamentals은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“이벤트 선언하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Web3 & DApp Development Fundamentals 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Web3 & DApp Development Fundamentals 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 이벤트 선언하기
  2. 인덱싱된 매개변수
  3. 이벤트 수신하기
  4. 이벤트와 스토리지 비교
← Web3 & DApp Development Fundamentals(으)로 돌아가기