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
  • How it works
  • Methods
  • Unique ID

Was this helpful?

  1. Features

Smart Contracts 👩🏾‍🔬

Connecting to Smart Contracts

Previous3box 👯‍♂️NextAdding Smart Contracts 🏗️

Last updated 4 years ago

Was this helpful?

DappHero is currently in BETA meaning things might not always work. Please be careful about using it on Mainnet and inform your users to also double check their transactions before confirming.

Traditionally to connect to smart contracts in your website you needed to import javascript libraries into the browser, create a large amount of custom javascript code, and be careful to check for a wide range of conditions. DappHero makes connecting to smart contracts painless and simplifies this task enormously so that you can focus on what you are building, rather than how to build it.

A DappHero project can be used to connect to any number of smart contracts, there's no limit!

To get started with Smart Contracts, let's quickly review some basics before diving into more detail.

How it works

Interacting with custom smart contracts generally takes five steps:

Read the following paragraphs about Unique ID's to understand how functionality is grouped in DappHero.

Methods

Smart contracts are made up of methods, (think of functions if you have a programing background) which allow you to interact with the state of the blockchain. You can retrieve information or send information to the blockchain using methods.

Interacting with smart contracts in DappHero is organized around interacting with specific smart contract methods. Each method does something specific, and you can connect to as few or as many methods of a smart contract as you like on your website. In this way, DappHero represents each method for each contract as a method instance. In practice this makes it very easy to work with smart contracts, as you don't need to worry about the entire smart contract, only the methods you wish to use.

Learn more about .

Unique ID

CustomContracts methods are different than other DappHero features as their functionality requires multiple components. Unlike Network or User features which require only one tag to identify an element and replace its data, CustomContracts require a variable number of elements that can potentially be located anywhere on the screen.

To account for the fact that you can put your elements for a CustomContract anywhere on the page, we have introduced a special tag, data-dh-property-method-id, which has a custom unique value that you determine, and which should be used for all elements related to the same functionality.

// This tag gives information about the method instance
<div ...
data-dh-property-method-id="myUniqueTag"
....
/>

// This element is where you define the input
<input ...
data-dh-property-method-id="myUniqueTag"
...
/>

// This button will invoke the method
<button ...
data-dh-property-method-id="myUniqueTag"
...
/>

// This element will display the output
<div ...
data-dh-property-method-id="myUniqueTag"
...
/>

In the above example, all the elements for a Custom Contract integration are marked with the same unique tag id, myUniqueTag in this way, the DappHero Engine knows all these different elements, regardless of where they are on the page, belong together in the same functionality.

Add a Smart Contract to your project on dapphero.io
Create a Method Instance element in your website
Create your input elements
Decide how your method is invoked
Display the outputs
Creating a Method Instance