Skip to main content

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. To deploy a smart contract from Dashboard, see Deploying a smart contract.

Starton provides you with a library of smart contracts templates. To start let's create your own token.

You will need:

Creating an Application project

  1. Create a directory for your app.
  2. Create a directory named src.
  3. In your terminal, install the express package using npm i express
  4. In src, create a index.js file.
  5. In index.js, enter the following lines to set up a port for your project:
const express = require("express")
const routes = require("./routes")
const app = express()
app.use(bodyParser.json())
const port = 3001 // Port of the project

app.set("port", port) // Set the port of the project
app.use("/", routes)
app.listen(port, () => {
console.log(`Server listening on port ${port}`)
})

This will deploy your app on port 3001.

Now for the good part, let's connect Starton to your application.

Connecting Starton to your application

  1. In src, create a routes.js file.

    const express = require("express")
    const axios = require("axios")
    const router = express.Router()
  2. In it, first authenticate with your API KEY.

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

Deploying your first Smart contract

To create a smart contract from the code of your application, use the following snippet. You can find the full list of endpoints in our API reference. Find more information about smart contracts parameters in the smart contract references section.

 // DEPLOYING YOUR SMART CONTRACT
axiosInstance
.post("/v3/smart-contract/from-template", {
network: "binance-testnet",
signerWallet: "0x0000000000000000000000000000000000000000",
templateId: "ERC20_META_TRANSACTION",
name: "My first smart token",
description: "This is the first smart contract I deploy. ",
params: ["My first token ", "MFT", "1000000000", "0x0000000000000000000000000000000000000000"],
speed: "average",
})
.then((response) => {
console.log(response.data)
})
  1. Display a message on your localhost:3001 to inform you that the transaction is successful.

    router.get("/", (req, res) => {
    res.send("Upload successful")
    })

    module.exports = router

Starting your application

  1. In your terminal, run node src.

You deployed your first smart contract with Starton. Congratulations!

Now that you've created your app, you can interact with your smart contract.

Interacting with your first Smart contract

To check that everything went your way, you can see the activity of your Smart contract.

You can interact with the smart contract we just created. To start, we will call a simple function to put our contract in a pause state.

To get notified of the transactions of your smart contracts, you can also create a watcher.

To interact with your smart contract from the code of your application, use the following snippet. You can find the full list of endpoints in our API reference.

const axios = require("axios")

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

axiosInstance
.post("/v3/smart-contract/binance-testnet/0x6Ea6e02a3C3dA7C690f1169C4e3e11a413875307/call", {
functionName: "pause",
params: [],
signerWallet: "0x5CCa311b2DFe4EDeA94a4aF086cA9954d3c06d23",
speed: "average",
})
.then((response) => {
console.log(response.data)
})

Related topics