🛠️Deploy Contracts

Explains how to deploy contract using the SDK.

Deployment process is quite similar to executing the contract function explained in the previous chapter.

It consists of the three steps:

  • Create deployment request

  • Redirect the user to the link generated for this concrete deployment request

  • Wait for the user to complete the action and receive the deployed contract instance

Before creating the deployment request, you must decide on the type of the contract you'd like to deploy. All the supported contract types are listed on the Dev3 Dashboard, so make sure you've created your first project before moving on.

In the example above, it is shown how to find the list of the deployable contracts. We then selected one item from the list, of type ERC20 Mintable, and found its contract ID (highlighted at the end of the video): openzeppelin.erc20presetmintableburnabledummy

Contract ID is the unique indentifier of the smart contract implementation within the Dev3 Platform. Usually it contains the two parts: organization and and the implementation name.

For example:

"openzeppelin.erc20presetmintableburnabledummy"

references the ERC20PresetMintableBurnable dummy token (used for testing) created from the OpenZeppelin Smart Contracts collection.

The source code of this contract, but also of all of the other ones, can be found in the central Dev3 contracts collection. The collection folder structure translates to the contract ID. For the contract from example above, all of the data used for deployment is stored in the

🗂​/contracts/openzeppelin/erc20presetmintableburnabledummy

If you'd like to see your contract in the collection, simply follow our guidelines and make a contribution which in turn will expose your contract on the platform, assign it a unique ID and let others (you included) deploy the contract instance using the Dashboard *OR* the SDK.

Now that you've found the contract ID, and obtained the SDK instance object (as explained in the initialization section), run the following steps to get the contract deployed:

// sdk object initialized as explained in the Initialization section

// 1) load contract manifest
const contractId = '<contract id found on the dashboard>';
const contractManifest = await sdk.getManifestById(contractId);

// 2) build the deployment request
const contractAlias = '<contract alias of your choice>'; // this will be used as your deployment identifier
const constructorParams = [
    // <list of constructor params>
];
const deploymentOptions = {};
const deploymentRequest = await contractManifest.buildDeployment(
    contractAlias,
    constructorParams,
    options
);
// deployment link is generated, redirect the user to execute the deployment
window.open(deploymentRequest.actionUrl, "_blank");

// 3) await the action completion
const contractInstance = await deploymentRequest.awaitResult();

// 4) you're done!
// you can now use the contractInstance object to interact with the contract,
// read the state, or execute functions (explained in chapters before)

Two things to note here:

Constructor parameters array used for initializing the contract is built the same way as when calling the functions on the smart contract. You can see the different possibilities here. You can see the list of the constructor parameters you have to provide in the same screen where you found the contract ID for the contract you wish to deploy. In the video above, for example, after we've opened the 'Create' screen for the token we want to deploy, we can see that there are two constructor parameters we have to provide: Token Name and the Token Symbol, just below the contract alias field. These two values we have to provide when building the deployment action.

Options object provided when building the deployment action can contain the following:

{
    ethAmount?: string;
    arbitraryData?: Map<string, object>;
    screenConfig?: ScreenConfig;
    callerAddress?: string;
    redirectUrl?: string;
}

All the fields are optional and can all be skipped by passing an empty object as the configuration. However, if you wish to use some (or all) of these, more detail is given in the options section.

Last updated