Embark Labs

Embark 5.2

In this release of Embark we introduce some new features such as proxy contract support and scripts execution. We’re also introducing some important deprecation warnings in preparation for Embark 6.0. We are making Embark lighter and more modular and to that end some modules that come by default will become optional plugins instead.

Proxy Contract Support

Proxy contracts are powerful tools usually used in more complex Dapps. They can be used for smart contracts that can be upgraded or to alleviate the deploy cost of multiple instances of a contract.

However, interacting with Proxy contracts is usually difficult, because you have to point the base contract to the address of the Proxy for it to work.

Not anymore! Embark now supports a contract configuration named proxyFor.

With it, you can specify that a Proxy contract is, well, a proxy for another one. Here’s an example:

deploy: {
Proxy: {
deploy: false
},
BaseContract: {
args: ["whatever the base contract needs"]
},
ContractInstance: {
instanceOf: "Proxy",
proxyFor: "BaseContract",
args: ["0x", "$BaseContract"]
}
}

With this configuration, our ContractInstance is an instanceOf Proxy and a proxyFor BaseContract.
This is why we point to BaseContract in the ContractInstance arguments.
The arguments themselves depend on the implementations of your BaseContract and Proxy contract.

Note that you could have used Proxy itself as a proxyFor BaseContract, but it’s usually more intuitive to use instanceOf and then resolve the contract instance with the new name you gave it (ContractInstance in this case).

Once the smart contracts are deployed, all you have to do is:

import ContractInstance from 'path/to/artifacts/contracts/ContractInstance';

For more information check the documentation for Proxy Contract Support

Scripts Runner

Embark uses a powerful declarative configuration of smart contracts. The parameters of smart contracts, how they relate to each other, what actions to do when they are deployed are described in a declarative configuration file and Embark then takes care of deploying the smart contracts in a way that reflects the configuration described.

Although this system covers the vast majority of cases, there are some situations where having the ability to execute scripts separately is useful, to that end Embark 5.2 now includes support for scripts, this can be used as migrations or as isolated scripts.

A script is really just a file with an exported function that has special dependencies injected into it. Here’s what it could look like:

modules.exports = async ({ contracts, web3, logger}) => {
...
};

The injected parameters are:

Scripts can be located anywhere on your machine, but should most likely live inside your project’s file tree in a dedicated folder.

To run a script, use the CLI exec command and specify an environment as well as the script to be executed:

$ embark exec development scripts/001.js

The command above will execute the function in scripts/001.js and ensures that Smart Contracts are deployed in the development environment.

If you have multiple scripts that should run in order, it’s also possible to specify the directory in which they live in:

$ embark exec development scripts

Embark will then find all script files inside the specified directory (in this case scripts) and then run them one by one. If any of the scripts fails by emitting an error, Embark will abort the execution. Scripts are executed in sequence, which means all following scripts won’t be executed in case of an error.

Tracking scripts

Just like Smart Contract deployments are tracked, (migration) scripts can be tracked as well. Since scripts can be one-off operations, Embark will not track whether they have been executed by default. Users are always able to run a script using the exec command as discussed in the previous sections.

To have Embark “remember” that a certain script was already run, you can use the --track option of the exec command, which will force tracking for this particular script:

$ embark exec development scripts/001.js --track

If we try to run the script again with the --track option, Embark will notice that the script has already been executed and tell us that it’s “already done”.

$ embark exec development scripts/001.js --track
.. 001.js already done

If however, we don’t provide the --track flag, Embark will execute the script as usual.

For cases in which we do want to track a set of scripts, especially when the main use case are migration operations, we can put our scripts in a special “migrations” directory. All scripts inside that directory will be tracked by default.

The directory can be specified using the migrations property in your project’s embark.json:

{
...
migrations: 'migrations'
}

If no such property is specified, Embark will default to “migrations”. Running any script or set of scripts is then automatically tracked.

For more information check the documentation for Deployment scripts

Support using $accounts in ens registrations

It’s now possible to specify an account to be registered as an ENS domain:

config({
namesystem: {
enabled: true,
register: {
rootDomain: "embark.eth",
subdomains: {
"mytoken": "$MyToken",
"account": "$accounts[0]"
}
}
}
})

Improved compatibility

In the test suite, in order to improve compatbility with other tools, it is now possible to also use the artifacts.require as an alternative to get a smart contract instances:

const AnotherStorage = artifacts.require('AnotherStorage');

Transition to Embark 6.0

To make Embark even lighter and faster, starting in Embark 6.0, the following will be installable plugins that will no longer come with Embark by default:

Embark 5.2 will issue warnings about these needing to be installed & configured as plugins to make transition to Embark 6.0 easier.

To make current projects compatible, ensure embark is added as a devDependency to your project, as well as any plugins. For e.g

In package.json add "embark-geth": "^5.2.2", to the devDependencies section and in embark.json add "embark-geth": {} to the plugins section

Next

Stay tuned for Embark 6.0 and the latest changes happening by watching the Embark GitHub repository and following us on the Embark Labs Twitter!

changelog

Features

Bug Fixes