Deploying your first

Smart contract on

Matchain

Welcome to the Matchain-Mainnet smart contract deployment tutorial! Follow these steps to deploy your first smart contract using Starton.
Let's create a project to deploy a smart contract from Code with Starton's API.

Step 1 - Initialize the project

1

Start by creating a directory for your project:

bash mkdir matchain-deploy

2

Then, get into your project directory:

bash cd matchain-deploy

3

With your project directory set up, install the dependencies:

bash npm add axios

4

Then, use touch to create a index.js file and open it with your favorite editor.

bash touch list.js

Step 2 - Add starton to your project

1

First, import axios

jsx const axios = require("axios")
2

Then, initialize axios using Starton URL and authenticate with your API KEY.To create an API key, go to the Deploying your first Smart contract on Matchain Developer section

const starton = axios.create({
 baseURL: "https://api.starton.com",
 headers: {
 "x-api-key": "YOUR API KEY",
 },
})

Step 3 - Creating a wallet

Before we can continue you will need a backend Wallet to sign our transaction

Backend Wallet

Backend Wallet uses a KMS. Meta mask is unavailable when using Start on from code. Since it is a browser extension,Start on API cannot access it from your project.

For more information, see:
Understanding Key Management Systems

We recommend you to create your wallet on Starton web application, but you canalso create it from code if you'd like to automate it.

1. Go to Matchain Dashboard, and click Wallet.

2. Click + Wallet.

Step 4 - Deploy your ERC20 token

For this tutorial, you will deploy your own ERC20 token.
Start on provides you with a library of smart contracts templates.
Learn more.

1. Now, let's write your first API call!

starton.post("/v3/smart-contract/from-template", {
 "network": "matchain-mainnet", // you can choose any network
 "signerWallet": "YOUR STARTON WALLET", // This will be the w
 "templateId": "ERC20_META_TRANSACTION", // you can choose an
 "name": "My first smart token", // the name that will be dis
 "description": "This is the first smart contract I deploy. "
 "params": [
 "My first token ", // Your smart contract name, on chain
 "MFT", // the symbol of your token
 "10000" + "000000000000000000", // 10000 token supply +
 "ANY WALLET YOU WANT" // The wallet that will receive th
 ],
 "speed": "average", // The fees you will pay on chain. More
}).then((response) => {
 console.log({
 transactionHash: response.data.transaction.transactionHa
 smartContractAddress: response.data.smartContract.addres

Congratulations on your first request.


Let's dive into what we just did:

  • The endpoint/v3/smart-contract/from-template allows you to deploy audited smart contracts. You can also deploy smart contract your own code, or import an existing contract Deploying your first Smart contract on Matchain 4- We used the Start on KMS to sign the transaction and pay gas fee. This allows you to automate transactions, but also to sponsor the end-user fees with gas less transaction
  • We used a ERC20 template. You can find more templates in Start on Library
  • We had to put 18 zeros after "10000" as the smart contract will read the amount in we i (the equivalent of cents, except there are 18 decimals and not 2).
  • We selected an average speed for your transaction. But with Starton everything is customizable. You can also set up a gas strategy to automate the management of your transactions.

2. Almost done! Now we can execute it to get our first contract deployed

bash node list.js

3. Check all of your transactions on Matchain Web Application

Congratulations on deploying your first smart contract!
In this tutorial, you discovered how to deploy your first smart contract but this is only the first step.

Start Building on Matchain Today

Dive into our comprehensive developer resources and join the ranks of innovative projects shaping the future.