Skip to main content
Tutorial
Beginner

Deploying your first Smart contract

You can use Starton to integrate blockchain into your application in a few steps. Let's create a project to deploy a smart contract from Code with Starton's API.

not a developer?

To follow this tutorial, you will need coding experience. If it's not your case, you can still deploy your smart contract:

Step 1 - Initialize the project

  1. Start by creating a directory for your project:

    mkdir starton-deploy
  2. Then, get into your project directory:

    cd starton-deploy
  3. With your project directory set up, install the dependencies:

    npm add axios
  4. Then, usetouch to create a index.js file and open it with your favorite editor.

    touch list.js

Step 2 - Add starton to your project

  1. First, import axios.

    const axios = require("axios")
  2. Then, initialize axios using Starton URL and authenticate with your API KEY.

    Create an API key


       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 Starton Wallet to sign our transaction.

Starton Wallet

Starton Wallet uses a KMS. Metamask is unavailable when using 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 can also create it from code if you'd like to automate it.

  1. From Dashboard, go to Wallet.
  2. Click + Wallet.


Faucet

To interact with the blockchain you will need the native currency of this blockchain to pay the gas fees. On the testnet, you can claim free faucet here

Step 4 - Deploy your ERC20 token

Starton Library

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

Now, let's write your first API call!

starton.post("/v3/smart-contract/from-template", {
"network": "binance-testnet", // you can choose any network
"signerWallet": "YOUR STARTON WALLET", // This will be the wallet that pay the fee. Must be on starton, cannot be a Metamask wallet
"templateId": "ERC20_META_TRANSACTION", // you can choose another template
"name": "My first smart token", // the name that will be displayed on the dashboard, not on chain
"description": "This is the first smart contract I deploy. ", // same, dashboard description and optional
"params": [
"My first token ", // Your smart contract name, on chain
"MFT", // the symbol of your token
"10000" + "000000000000000000", // 10000 token supply + 18 zero.
"ANY WALLET YOU WANT" // The wallet that will receive the token supply, can be a starton wallet or metamask
],
"speed": "average", // The fees you will pay on chain. More info HERE
}).then((response) => {
console.log({
transactionHash: response.data.transaction.transactionHash,
smartContractAddress: response.data.smartContract.address,
explorer: `https://testnet.bscscan.com/tx/${response.data.transaction.transactionHash}`
})
}).catch(error => console.error(error.response.data))

Congratulations on your first request. Let's dive into what we just did:

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

node list.js

And voilà, your first contract is deployed!

{
"transactionHash": "0x43462af8448e34ea5cddbb73b4dcf5c0c04fa6155111273a1573ec6c4c9a59e8",
"smartContractAddress": "0xB4B4a180f065b2461eF64359909fb0cfCb04D986",
"explorer": "https://testnet.bscscan.com/tx/0x43462af8448e34ea5cddbb73b4dcf5c0c04fa6155111273a1573ec6c4c9a59e8"
}

Check all of your transactions on Starton 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.

Learn how to

Loubna Benzaama

Lead technical writer


Created:

December 21, 2023

Reading time:

5 min


Content
  • Step 1 - Initialize the project
  • Step 2 - Add starton to your project
  • Step 3 - Creating a wallet
  • Step 4 - Deploy your ERC20 token