Skip to content

Add env.me() alias for env.current_contract_address()#1777

Closed
leighmcculloch wants to merge 4 commits intomainfrom
add-env-me-alias
Closed

Add env.me() alias for env.current_contract_address()#1777
leighmcculloch wants to merge 4 commits intomainfrom
add-env-me-alias

Conversation

@leighmcculloch
Copy link
Copy Markdown
Member

@leighmcculloch leighmcculloch commented Mar 19, 2026

What

Add me() as an #[inline(always)] alias for current_contract_address() on Env. Both methods include cross-reference documentation linking to each other. A test verifies that both methods return the same address.

Why

current_contract_address() is verbose for a frequently used call. me() provides a shorter, more readable alternative at no cost. Typically we'd avoid having two ways to do something in the SDK, but there's no reason to mark the longer fn as deprecated so this change does not do that.

Close #1778

@leighmcculloch leighmcculloch requested a review from a team March 19, 2026 06:39
@tupui
Copy link
Copy Markdown

tupui commented Mar 19, 2026

In my mind "me" refers to a person. Not a native speaker but I think we should consider another more neutral word like "this" or just "contract".

@leighmcculloch
Copy link
Copy Markdown
Member Author

leighmcculloch commented Mar 19, 2026

Maybe we can find a better term that's easier understand regardless of whether someone is a native speaker or not.

Here examples of what the same or similar function is named in other contract system:

Language Platform Command/Function
Solidity Ethereum/EVM address(this)
Vyper Ethereum/EVM self
Yul Ethereum/EVM address()
Fe Ethereum/EVM ctx.self_address()
Huff Ethereum/EVM address
Rust (Solana/Anchor) Solana ctx.program_id
Rust (ink!) Polkadot/Substrate self.env().account_id()
Rust (CosmWasm) Cosmos env.contract.address
Rust (NEAR SDK) NEAR env::current_account_id()
Rust (MultiversX/Elrond) MultiversX self.blockchain().get_sc_address()
Rust (Stylus) Arbitrum/EVM contract::address()
TEAL Algorand global CurrentApplicationID
PyTeal Algorand Global.current_application_id()
Tealish Algorand Global.CurrentApplicationID
Michelson Tezos SELF_ADDRESS
SmartPy Tezos sp.self_address()
LIGO Tezos Tezos.get_self_address()
Archetype Tezos selfaddress
Cadence Flow self.account.address
Move (Aptos) Aptos @module_address (named address)
Move (Sui) Sui object::id(&self)
Plutus (Haskell) Cardano ownCurrencySymbol / scriptContextTxInfo
Aiken Cardano Accessed via the ScriptContext datum
FunC TON my_address()
Tact TON myAddress()
Fift TON my_address
Clarity Stacks/Bitcoin (as-contract tx-sender)
Scilla Zilliqa _this_address
Ride Waves this
Cairo StarkNet get_contract_address()
Sway Fuel ContractId::this()

@leighmcculloch leighmcculloch requested a review from mootz12 March 19, 2026 09:15
@tupui
Copy link
Copy Markdown

tupui commented Mar 19, 2026

Oh nice table!

env.contract or env.address sound nice to me. I also like a bit self and this. But maybe too on the side of referring to an object in general.

@kalepail
Copy link
Copy Markdown

kalepail commented Mar 19, 2026

Came here to say what tupui is saying. My vote is self or self_address to ensure it's clear what the contents is. me could get confusing imo conflicting with other function args for things like user.

@leighmcculloch
Copy link
Copy Markdown
Member Author

self isn't allowed in Rust. this is, but looking at other chains the table above, maybe env.address() would suffice.

@dmkozh
Copy link
Copy Markdown
Contributor

dmkozh commented Mar 19, 2026

but looking at other chains the table above, maybe env.address() would suffice.

I think env.address() is rather confusing. Something like self.address()/self.account.address is very different from env.address() which may imply that we're asking for address of the env, which is undefined. For an env method we need some pointer at the current contract, like my_address/self_address/curr_address.

@tupui
Copy link
Copy Markdown

tupui commented Mar 19, 2026

Yeah but I think here you might have a bias of knowing too much about intervals 😅

If not for the contract address, I am not sure what else env.address could mean?? curr_address or this_address could work too IMO if less confusing. Just slightly longer.

@leighmcculloch
Copy link
Copy Markdown
Member Author

I'm starting to get a good sense of how we ended up with the current function. I'm closing this pull request. There's an issue open at #1778. If anyone thinks of better fn names, post it there please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add short alias for Env current_contract_address()

4 participants