Deploy a smart contract with Starton Connect

For this first tutorial, we’ll use Starton Connect to create our own crypto token !

Deploy a smart contract with Starton Connect

Deploy a smart contract from code using Starton Connect

For this first tutorial, we’ll use Starton Connect to create our own crypto token!

In order to do this, we’ll be deploying a smart contract using Deploy.

We’ll do it directly from our code and our contract will be an instance of an audited premade template proposed by Starton.

The language used will be Javascript but any language would work in a similar manner.


1) Get the list of available templates

Before deploying our contract let’s get the list of templates in order to find one that suits our need.

To do this, we’ll need to query Connect’s API and to authenticate ourselves using an API key.

We can create an API key from the dashboard in the Developer section.
Using this API key we can call the API with the following JS code :

const axios = require("axios")
const http = axios.create({    
    baseURL: "https://api.starton.io/v3",
    headers: {        
        "x-api-key": ‘YOUR_API_KEY’,    
    },
 })
        
http.get('/smart-contract-template').then(response => {    console.log(response.data)
})

Be sure to replace the x-api-key value by your own API key !

When querying the API we should get back a list of template items in which we can find for example :

{  
"id": "ERC20_META_TRANSACTION",  
"name": "ERC20", 
"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 we’ll use for our crypto token.

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


2) Choose a Network and fuel your wallet

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

The compatible networks 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.

It is now important 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 for the gas fees.

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

Here, it is the ethereum-goerli network.

We can now claim free faucet here : https://faucet.dimensions.network/

Just put your address there and click on “Send me test Ether” and wait for the transaction to complete.


3) 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 and 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):

http.post('/smart-contract/from-template', { 
    "network": "ethereum-goerli",  
    "templateId": "sct_d3747a1f0b8b4de0a2e72665cfafcbec",  
    "name": "DemoToken",  
    "description": "Our own crypto token.",  
    "params": ["1000000", "DemoToken", "DEMO"]
    }).then(response => {    
    console.log(response.data)
    })

The expected result :

{ 
"id": "sc_24dce9e26a7d46a7b707e257a6a6cfb2",  
"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)"
}

If it worked congrats ! You just created your own crypto token in a few minutes and with a minimal amount of code.


4) Checking the contract creation

Most blockchains propose a blockchain explorer so we can inspect the state and history of the blockchain.

We can thus use the previously returned address and creation hash to check for our contract’s status on the blockchain.

For Goerli, we can go on https://goerli.etherscan.io/ to inspect the blockchain.

Here we can see the summary of the transaction created for the deployment of our contract (using the creationHash in the url).

We can also track here our new DEMO token.

Or more generally, we can use the address of the contract to find out how it interacted with the world : https://goerli.etherscan.io/address/0xDA96a733ec2C3eC1142A5A1Ef31cfd7755CAE037


5) Conclusion

Congratulations for completing this tutorial !

You now know how to use Deploy, how to fuel your wallet with test faucet, pick a network, deploy your contract and inspect the blockchain!

In the next tutorial, we’ll be exploring how we can interact with our newly created contract, for example in order to mint new tokens for our users.

We hope you enjoyed this tutorial.

See you on the next one !