Skip to main content

Deploying a Smart Contract from template

You can deploy a smart contract from templates directly from code using the Relayer or using the Dashboard.

Before deployment, you can get the list of templates from our API.

Get the list of available templates

Let's find the template that suits your need.

To do this, you can query Starton’s API. First you need to authenticate using an API key.

Create an API key from the dashboard in the Developer section. Using this API key, we can make a call using the following JS code:

const axios = require("axios")

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

startonAPI
.get("/v3/smart-contract-template")
.then((res) => console.log(res.data))
.catch((e) => console.log(e))

Be sure to replace x-api-key value with your own API key! When querying the API, it should return a list of template items:

{
"id": "ERC20_META_TRANSACTION",
"name": "ERC20 Fungible Token with fixed supply",
"description": "An ERC20 token contract keeps track of fungible tokens: any one token is exactly equal to any other token",
"tags": [...],
"blockchains": [...],
"bytecode": "string",
"constructorParams": [...],
"abi": [...],
"compilerVersion": "string",
"source": "string",
"isAudited": true,
"isActivated": true,
"createdAt": "string",
"updatedAt": "string"
}

This is the object associated with the template you can use to create a crypto token.

We’ll be using an ERC20 template as it is the standard for token creation on EVM based blockchains.

Choose a Network and fuel wallet

Now that we know which template to use, we also need to choose a network on which to deploy.

The compatible blockchains for this template can be seen inside the blockchain objects in the previously returned template object.

For example for the Ethereum blockchain there are multiple available networks such as ethereum-mainnet or ethereum-goerli (testnet).

We’ll choose to deploy our contract on the ethereum-goerli network. The list of supported blockchains and network is available in Overview.

Note that is it crucial that we fuel our wallet with some Ether faucet. Otherwise the blockchain will reject our smart contract’s deployment as we will lack funds to cover the gas fees.

In order to claim test faucets we need to go on the Wallet section on Connect’s dashboard and find the address associated to the network we are interested in.

Here, it is the ethereum-goerli network.

We can now claim free faucet on the official Ethereum faucet website. Enter your address, click Send me test Ether and wait for the transaction to complete.

Deploying the contract

Everything is now in place so we can create an instance of the smart contract template we picked.

We’ll use the ID of the template we got in order to tell Deploy which template to use for the contract creation.

We also need to provide values for the parameters of our smart contract’s constructor.

For our ERC20, we’ll need to provide:

  • a name for our token
  • a ticker
  • the initial supply

Let’s call our token the DemoToken, with DEMO as its ticker and an initial supply of 1.000.000 tokens.

Here is the code to deploy the contract (Axios being configured as before):

const axios = require("axios")

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

startonAPI
.post("/v3/smart-contract/from-template", {
network: "polygon-mumbai",
templateId: "ERC20_MINT_META_TRANSACTION",
name: "My token with starton",
signerWallet: "0x694F07CEEc0869aa0dB5E8157FA538268F28B23f",
description: "Description on my token",
params: ["DemoToken", "DEMO", "1000000000000000000000000", "0x694F07CEEc0869aa0dB5E8157FA538268F28B23f"],
})
.then((res) => console.log(res.data))
.catch((e) => console.log(e))

The expected result:

{
"id": "ERC20_META_TRANSACTION",
"name": "DemoToken",
"description": "Our own crypto token.",
"network": "ethereum-goerli",
"bytecode": " … ",
"abi": [],
"projectId": "prj_f2108b28949d47898a39939cbc7277c3",
"address": "0xDA96a733ec2C3eC1142A5A1Ef31cfd7755CAE037",
"creationHash": "0xef4313209959d6441e14db5d43905f674a78adba2173b522b7fe37311e135c05",
"createdAt": "Tue Jun 29 2021 13:09:17 GMT+0000 (Coordinated Universal Time)",
"updatedAt": "Tue Jun 29 2021 13:09:17 GMT+0000 (Coordinated Universal Time)"
}

Related topics