Smart Contracts: Flow
Engage your Elements application or game with the Flow blockchain using smart contracts.
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 Cadence code to the chain. Elements will, just in time, insert the appropriate import statements 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 Wallet Account ID to find the contract.
Assuming you have two Flow Smart Contracts:
Assuming they were deployed to the account with the ID:
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.
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.
The final script sent to Flow will look like this:
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:
This will result in Elemetns automatically generating the following header just in time.
Therefore, only MyFirstContract
will not collide with any other imports. The following script must only reference that contract.
The final script sent to Flow will look like this:
Last updated