Contract Deployment(Starton)

Already know what you're doing?

  • RPC URL: https://rpc.matchain.io

  • ChainID: 698

  • Bridge or request gas sponsorship from our team

Welcome to the Matchain Mainnet smart contract deployment tutorial! Follow these steps to deploy your first smart contract using Starton. If you would prefer to use Remix, check out this guide. Let's create a project to deploy a smart contract from code using Starton's API.

Step 1 - Initialize the project

1. Start by creating a directory for your project:

Copy

bash mkdir matchain-deploy

2. Then, get into your project directory:

Copy

bash cd matchain-deploy

3. With your project directory set up, install the dependencies:

Copy

bash npm add axios

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

Copy

bash touch list.js

Step 2 - Add starton to your project

1. First, import axios

Copy

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

Copy

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. Metamask is unavailable whenusing Starton from code. Since it is a browser extension,Starton 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. Starton provides you with a library of smart contracts templates. Learn more.

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

Copy

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

 })
}).catch(error => console.error(error.response.data))

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 Starton KMS to sign the transaction and pay gas fee. This allows you to automatetransactions, but also to sponsor the end-user fees with gas less transaction - We used a ERC20 template. You can find more templates inStarton Library - We had to put 18 zeros after "10000" as the smart contract will read the amount in wei (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

Copy

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.

Last updated

Logo

All Rights Reserved © 2024 Matchain