Elements Manual
Elements 2 Manual
Elements 2 Manual
  • Welcome 👋
  • QUICK START
    • Elements in Five Minutes or Less
  • General
    • General Concepts
    • N-Tier Architecture
    • Security Model
  • SCRIPTING ENGINE
    • Scripting Engine Overview
      • Intro to Resources and Cloud Functions
      • Horizontal Scaling Model
      • Database Access
      • Server-to-Server API Calls
      • Deploy Cloud Functions via Git
      • Creating and Destroying Resources
      • Cross-Resource Invocation
      • Indexing Resources
      • Coroutines
      • Manifest
  • Core Features
    • Core API Overview
    • Sessions
    • Applications
      • Facebook Application Configuration
      • Firebase Application Configuration
      • Amazon GameOn Application Configuration
      • iOS Application Configuration
      • Android Application Configuration
      • Matchmaking Application Configuration [deprecated]
    • Users and Profiles
    • Digital Goods
    • Progress and Missions
    • Leaderboards
    • Matchmaking
    • Followers
    • Friends
    • Reward Issuance
    • Push Notifications
    • Auth Schemes
    • Save Data
    • Schemas and Metadata Specifications
    • Queries
      • Base Query Syntax
      • Boolean Queries
      • Object Graph Navigation
      • Advanced Operators
        • .ref
        • .name
  • Web 3
    • Omni Chain Support
    • Vaults
    • Wallets
    • Smart Contracts
      • Smart Contracts: Ethereum
      • Smart Contracts: Flow
      • Smart Contracts: Solana
      • Smart Contracts: Neo
    • Know Your Customer
      • Formidium
  • CONFIGURATION
    • Using the Web Console
    • iOS and Android Product Bundles
    • Direct Database Access and Batch Configuration
  • UNITY PLUG-INS
    • Unity Plugin
    • Content Delivery Management and Unity CDN Plugin
  • DEPLOYMENT
    • Deployment Overview
      • Docker Containers
      • AWS Deployment
      • Standalone docker-compose
  • LUA SAMPLES
    • lua Samples
      • main.lua
      • event.lua
      • hello_world.lua
      • model.lua
      • startup.lua
      • HTTP Manifest
        • Example endpoint handler
        • Example operations table
  • RESTful APIs
    • Swagger and Swagger UI
    • Elements 3.0.X (Preview)
      • Applications
      • Friends and Followers
      • Digital Goods and Inventory
      • Leaderboards
      • Missions and Rewards
      • User and Profiles
      • Save Data
      • Custom Metadata
Powered by GitBook
On this page
  • Specify all Contracts
  • Specifying a Specific Contract
  1. Web 3
  2. Smart Contracts

Smart Contracts: Flow

Engage your Elements application or game with the Flow blockchain using smart contracts.

PreviousSmart Contracts: EthereumNextSmart Contracts: Solana

Last updated 2 years ago

Flow aggregates all contracts in a single Account. Unlike other SDKs, it is not possible to simply invoke methods on smart contracts without passing a small bit of code to the chain. Elements will, just in time, insert the appropriate to the Cadence code which you supply using the scripting engine.

In order to separate the contract address from the code, Elements provides two options when defining a flow contract address. In both cases, we use the flow to find the contract.

Assuming you have two Flow Smart Contracts:

pub contract MyFirstContract { /*...*/ }
pub contract MySecondContract { /*...*/ }

Assuming they were deployed to the account with the ID:

0xf8d6e0586b0a20c7

Specify all Contracts

When specifying a Flow account, you may simply specify the address of the account. This will result in an import statement which will import all contracts within the account. Elemetns will generate the following header just in time.

import 0xf8d6e0586b0a20c7

Therefore, both MyFirstContract and MySecondContract will be visible in the scope of the script. The following script will execute, assuming that both contracts have the appropriate methods.

MyFirstContract.foo()
MySecondContract.foo()

The final script sent to Flow will look like this:

import 0xf8d6e0586b0a20c7

MyFirstContract.foo()
MySecondContract.foo()

Specifying a Specific Contract

In some cases, you may wish to avoid colliding with names in the existing scope. In Cadence, thi sis typically done with the import from statement. To specify the import format, you can append the Account address with the name of the specific contract.

For example, to specify MyFirstContract you simply append :MyFirstContract to the Flow Address owning the contract to make the Elemetns addres. The final address in this example will look as follows:

0xf8d6e0586b0a20c7:MyFirstContract

This will result in Elemetns automatically generating the following header just in time.

import MyFirstContract from 0xf8d6e0586b0a20c7

Therefore, only MyFirstContract will not collide with any other imports. The following script must only reference that contract.

MyFirstContract.foo()

The final script sent to Flow will look like this:

import MyFirstContract from 0xf8d6e0586b0a20c7

MyFirstContract.foo()
Cadence
import statements
Wallet Account ID