From d62591ed61bda4c9278936a562b1d305df4db551 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Wed, 24 Jul 2024 02:32:15 +0200 Subject: [PATCH] feat: underscores as parameter names in receivers --- pages/book/contracts.mdx | 12 ++++++++++++ pages/book/receive.mdx | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pages/book/contracts.mdx b/pages/book/contracts.mdx index 9fa4fad5..2eb4eb4d 100644 --- a/pages/book/contracts.mdx +++ b/pages/book/contracts.mdx @@ -305,6 +305,18 @@ contract HelloWorld { } ``` +Naming a parameter of the receiver function with an underscore `_{:tact}` makes its value considered unused and discarded. This is useful when you don't need to inspect the message received and you only want it to convey a specific opcode: + +```tact +message(42) UniverseCalls {} + +contract Example { + receive(_: UniverseCalls) { + // Got a Message with opcode 42 + } +} +``` + ### Internal functions These functions behave similarly to private methods in popular object-oriented languages — they're internal to contracts and can be called by prefixing them with a special [identifier `self{:tact}`](#field-access). That's why internal functions can sometimes be referred to as "contract methods". diff --git a/pages/book/receive.mdx b/pages/book/receive.mdx index 328c37cd..b62790be 100644 --- a/pages/book/receive.mdx +++ b/pages/book/receive.mdx @@ -37,3 +37,15 @@ contract MyContract { } } ``` + +Naming a parameter of the receiver function with an underscore `_{:tact}` makes its value considered unused and discarded. This is useful when you don't need to inspect the message received and you only want it to convey a specific opcode: + +```tact +message(42) UniverseCalls {} + +contract Example { + receive(_: UniverseCalls) { + // Got a Message with opcode 42 + } +} +```