DappHero Docs
  • Getting Started 👋🏽
  • DappHero Basics
    • How does it work? 🧐
    • Setting Up Your Project 🏗️
      • Projects
      • Smart Contracts
    • An Intro to Features 🎁
  • Features
    • Network ⛓️
    • User 🤖
    • 3box 👯‍♂️
    • Smart Contracts 👩🏾‍🔬
      • Adding Smart Contracts 🏗️
        • Contract Details
      • Create a Method Instance
      • Inputs
      • Invoke
      • Outputs
      • Events
      • Advanced: Automatically clearing Inputs
      • Advanced: Getting the Current User's Address Dynamically
      • Advanced: Sending ETH to a contract method
      • Listening to Events
      • Resources: Learn More
      • Resources: Test Contracts
    • Collectibles 🃏
      • Getting Started
      • Single Collectibles
      • Listing Collectibles
      • Displaying Token Metadata
      • Advanced: $CURRENT_USER
      • Advanced: $URL
      • Advanced: $THIS
      • Advanced: Properties
      • Calling Smart Contracts inside Collectibles
      • Collectible Example
  • No-Code Integrations
    • Webflow 🎁
      • Getting Started with Webflow
      • Add DappHero Elements
      • Learn more about WebFlow
  • Examples
    • Coming soon...
  • Advanced
    • Engine Events
    • Force Refresh
    • Database
    • Ethereum Provider
  • Updates
    • ChangeLog
  • Bug Bounty
Powered by GitBook
On this page

Was this helpful?

  1. Features
  2. Smart Contracts 👩🏾‍🔬

Advanced: Getting the Current User's Address Dynamically

Getting the value of the current user as an input

$CURRENT_USER

A common use case for many smart contracts is to return information from a public view method that is associated with the current user. An example would be retrieving the balance of the current users ERC20 token amount. While you could create a normal input field and let a user populate it with their address, for many use cases this would be an inconvenient solution where you might want to show some smart contract state related to the current user on page load.

To address this common use case, we have created the reserved keyword $CURRENT_USER that can be used inside of inputs for smart contracts.

<input
      data-dh-property-method-id="000"
      data-dh-property-input-name="<<input method argument name>>"
      value="$CURRENT_USER"
/>

In this example, the input field's value would be automatically populated with the value of the current users Ethereum address.

The $CURRENT_USER keyword is particularly useful when the input is hidden. To do this, set the display value of the input to none.

<input
      data-dh-property-method-id="000"
      data-dh-property-input-name="<<input method argument name>>"
      style="display:none;"
      value="$CURRENT_USER"
/>
PreviousAdvanced: Automatically clearing InputsNextAdvanced: Sending ETH to a contract method

Last updated 5 years ago

Was this helpful?