# Deploy Contracts

The `Acala EVM Playground` is useful to test various functionalities of Acala EVM. It’s a fork from parity `canvas-ui`.

## **1. Setup**

To deploy your smart contract you can use our testnet or you can run your local dev node.

### Run your own development network

To run your own development network, you can follow the [instructions](https://evmdocs.acala.network/network/network-setup/local-development-network) on setting up your own development network in the official EVM+ documentation.

Once your development network is operational, you can connect your EVM wallet to it by using the following parameters:

<table data-header-hidden><thead><tr><th>Key</th><th>Value</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Name</strong></td><td>Mandala</td><td></td></tr><tr><td><strong>URL</strong></td><td><code>http://127.0.0.1:8545</code></td><td></td></tr><tr><td><strong>Chain ID</strong></td><td>595</td><td></td></tr><tr><td><strong>WS endpoint URL</strong></td><td><code>ws://127.0.0.1:9944</code></td><td></td></tr><tr><td><strong>Symbol</strong></td><td>ACA</td><td></td></tr></tbody></table>

You can reference the [instructions](https://wiki.acala.network/build/development-guide/smart-contracts/get-started-evm/connect-to-a-node/use-metamask-with-evm+) on how to connect MetaMask to the EVM+ and substitute the values from instructions with the values from above.

After your EVM wallet is connected to the Acala EVM+, you can continue to the [EVM playground](https://evm.acala.network/).

### **Deploy to our test network**

To deploy to our test network you need to have the [polkadot{.js}](https://polkadot.js.org/extension/) wallet extension installed in your browser.

Once you have the extension installed, you can [bind your accounts](https://wiki.acala.network/build/development-guide/smart-contracts/evm-account#2.-bind-an-existing-ethereum-account) with an EVM address and get test network funds from the [Discord faucet](https://wiki.acala.network/build/development-guide/smart-contracts/get-started-evm/broken-reference).

{% hint style="info" %}
**Note:** For the remainder of this page we will assume you are using a local development network. If you are deploying to the test network.
{% endhint %}

## **2. Upload Contract ABI & bytecode**

To deploy a smart contract using [EVM playgrounds](https://evm.acala.network/), you need to compile your smart contract in your preferred development framework so that you have the ABI bundle available to upload.

<details>

<summary>How to create an <code>ExampleToken</code> ABI bundle</summary>

In case you want to use the same smart contract as it is used in this example, you can follow these short instructions on how to create it.

First clone the Acala Hardhat tutorials example:

```shell
git clone git@github.com:AcalaNetwork/hardhat-tutorials.git
```

Move into the examples repository and into the `token` example:

```shell
cd hardhat-tutorials/token
```

Within the example directory, install all of the dependencies and compile the smart contracts:

```shell
yarn && yarn build
```

This will compile the `Token` smart contract and create an ABI bundle to the directory `artifacts/contracts/Token.sol/` the bundle file is called `Token.json`.

</details>

Upload `ExampleToken` ABI & bytecode file by navigating to <https://evm.acala.network/>.

Go to the `Upload` tab.

![EVM playground => Upload](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FoC0jmqQBSvyGIigwSu2k%2Fimage.png?alt=media\&token=3e475e93-3a19-4a93-bd01-ad024edf59c4)

Assign the `Name` of your smart contract. You will be able to identify the smart contract in the `Deploy` tab with it, once it gets uploaded.

To upload the ABI bundle itself, you can either drag and drop it into the upload section, or click on the section and select the file.

![EVM playgrounds => Upload => Add file](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2Fral8DvhwhfQx7z6LzCN1%2Fimage.png?alt=media\&token=3cfa2537-cb98-463a-9ddd-47ce89273d4d)

Once you have selected the correct ABI bundle, the methods of the smart contract should be displayed. You can verify that the correct methods are listed and press `Upload` to upload the ABI bundle.

## **3. Deploy the Contract**

Smart contracts can be deployed under the [Deploy tab](https://evm.acala.network/#/deploy) of the EVM playgrounds.

The ABI bundles that you uploaded in the `Upload` tab can be seen here:

![EVM playgrounds => Deploy](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FlNbCTHTNKWZowkB9ANXb%2Fimage.png?alt=media\&token=a532c04d-ece4-4f55-87f8-0c31a770636a)

The methods available for an ABI bundle can be seen by expanding the `ABI` menu. This can be helpful if you have multiple bundles uploaded and you want to be sure that you will be interacting with the right one.

![EVM playgrounds => Deploy => Expand ABI section](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FyvucKjs59xFRx9Hm4R5S%2Fimage.png?alt=media\&token=16a1e34e-cbd0-45c0-b9f8-869568df709e)

When you have verified that you are interacting with the ABI bundle that has the correct methods available, you can click `Deploy`, which should open a deployment interface:

![EVM playgrounds => Deploy => Deploy selected ABI bundle](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FTVJcgwW1AV2VbH0yADDs%2Fimage.png?alt=media\&token=d43e5216-c7e1-4a68-b6cb-ee8ac21773b3)

The interface consists of the following components:

* Button to connect to your EVM wallet (this is why connecting MetaMask to the EVM+ is a prerequisite for this entry)
* Smart contract name, that can be changed, so you can deploy the same ABI bundle multiple times and easily differentiate between them
* ABI bundle identifications
* Fields to input the smart contract constructor parameters
* Value field to determine wether to send some of the native currency with the deploy transaction
* Fields to override the [`gas parameters`](https://evmdocs.acala.network/network/gas-parameters)
* `Deploy` button to deploy the smart contract once you are satisfied with the deployment parameters

### 1. Connect your EVM wallet

Pressing the <img src="https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FKj5zGTXdhurP5l8XqAZr%2Fimage.png?alt=media&#x26;token=2c8aa24a-85d0-4808-ab63-cc664c64776d" alt="" data-size="line"> button will prompt your EVM wallet to connect to the site. You can select the account that you want to use with the EVM playgrounds and connect it.

![](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2F03i11U4GhsppIp9n5Dw0%2Fimage.png?alt=media\&token=f654ad18-c31a-4f9f-b732-13cd81e6774c)![](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2F6ktlbxhvIRK3RvFNM22b%2Fimage.png?alt=media\&token=112693b4-55c6-46b9-9833-1bdab70f430f)

The selected account should be displayed at the top of the page now:

![Displayed deployment account](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FNzhQOKHEY9DvUofin8cI%2Fimage.png?alt=media\&token=3cb4fcf3-bd07-4c20-a2e3-fc9565e094d6)

### 2. Update the required deployment parameters

Depending on the requirements, you can modify the deployment parameters of your smart contract. It is required to fill out the constructor parameters, but modifying other values is optional.<br>

![Filled out deployment values](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAr4HPdeSWiuUx1XzEALT%2Fuploads%2F9wxhZ96rDiIYMPvpYUKb%2Fimage.png?alt=media\&token=9afddcce-b216-42e2-bd55-24a7c0cd5cad)

Once the values are filled out and double checked, the smart contract is ready to be deployed.

{% hint style="warning" %}
The `validUntil` field value has to be higher than the current block number, or the deployment transaction will fail, due to the validator treating it as outdated. You can verify the current block number in a [block explorer](https://evmdocs.acala.network/network/gas-parameters).
{% endhint %}

### 3. Deploy the smart contract

Once the parameters of deployment are ready, you can deploy the smart contract by pressing the `Deploy` button. This should prompt your EVM wallet to confirm your deployment transaction:<br>

![Confirming the deployment transaction](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAr4HPdeSWiuUx1XzEALT%2Fuploads%2FKRsWktz8uflxQILeGFkm%2Fimage.png?alt=media\&token=c5401b2a-5b30-4770-a1bf-018d1dd3fe2b)

Once the transaction is included in a block, the deployed smart contract can be found under `Execute` tab.

## **4. Interact with the Contract**

Navigate to the `Execute` tab. Find the deployed `ExampleToken` contract and Click the `Execute` button on the bottom of the "ExampleToken" box.

## **5. Query Balances**

To perform a query on an account's balance, do the following steps:

1. Make sure that the account you used to deploy the smart contract is connected to the `EVM playgrounds`.
2. Pick `balanceOf` from the `Message to Send` dropdown.
3. Copy and paste the address of the account that you used to deploy the smart contract to the `account: address` input.

![Filled out balance query](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2F9H8s0DhJWpZB9ky1ehaG%2Fimage.png?alt=media\&token=2129b1a5-2a41-4b86-859d-01dd05bd89dc)

{% hint style="info" %}
**Note:** Solidity smart contracts have two types of methods: `views` and `executable` methods.
{% endhint %}

* `Views` are used to query information from the blockchain without writing data to it. `Views` transactions are free. The Playground uses the `Call` button to indicate this.
* `Executable` methods can write data onto the blockchain, and these transactions aren’t free. Click the `Execute` button to execute it.

Finally, click `Call` at the bottom, and `Call results` should show the ExampleToken balance of `123456789`.

![Completed balance query](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FsWhyf3OUwDIhEt4GUEJx%2Fimage.png?alt=media\&token=6cf72fe8-5884-474c-9cdf-3a45d5f27d38)

## **6. Transfer**

Now let's try transferring ExampleTokens to another account.

1. Make sure that the deployer account is connected to the EVM playgrounds.
2. Select `transfer` from the `Message to Send` dropdown.
3. Fill out the `recipient address` input box with another EVM address to which to send the tokens.
4. Enter transfer amount in the `amount: unit256` argument box, note the token has a standard 18 decimals.
5. Click `Execute`.

![Filled out token transaction](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2Ff1W487t0KQijiwjT9tDL%2Fimage.png?alt=media\&token=f2125c4a-c8e4-425d-ad73-ac71e0499d55)

A notification will pop-up to confirm that the transaction is successfully executed.

Now you can check the balances of both of the accounts, and confirm that they have changed. deployer's account:

![Deployer's balance](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FH9QL7GwGlSXjEtzCKKuP%2Fimage.png?alt=media\&token=d045dce9-f666-486e-b355-667994688402)

Other account:

![Other account's balance](https://801616779-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAz4EenwXLth_HO_hmJ-887967055%2Fuploads%2FuGtNYaqjwYp3z7tteofT%2Fimage.png?alt=media\&token=4cfdf3a5-2612-4710-bbbb-6232aeff0ebf)
