Deploying a Smart Contract
To deploy a smart contract with Starton you have three options:
- Deploy a smart contract using an audited contract template from our library
- Deploy your own smart contract using its bytecode and ABI
- Import existing contract to view them on your dashboard and interact with them.
- From template
- From bytecode
- From on-chain contract
You can deploy a smart contract from templates directly from code using the Relayer or using the Dashboard.
- From Code
- From Webapp
To deploy a smart contract from the code of your application, use the following snippet. You can find the full list of templates in our API reference.
You will need the ID of the template we got in order to tell which template to use for the contract creation.
We also need to provide values for the parameters of our smart contract’s constructor.
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: "ethereum-sepolia",
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))
Here is the expected response:
{
"id": "ERC20_META_TRANSACTION",
"name": "DemoToken",
"description": "Our own crypto token.",
"network": "ethereum-sepolia",
"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)"
}
To learn more on how to deploy a smart contract from a template, see our full tutorial.
To deploy a smart contract from bytecode, you will need the ABI and bytecode of your contract. You can find the full Tutorial on how to get the bytecode and the ABI from your contract in our full Tutorial.
- From Code
- From Webapp
To deploy a smart contract from bytecode from your own backend, we'll use the following snippet:
const axios = require("axios")
const http = axios.create({
baseURL: "https://api.starton.com/v3",
headers: {
"x-api-key": 'YOUR_API_KEY',
},
})
http.post('v3/smart-contract/from-bytecode', {
"network": "binance-testnet",
"name": "My contract's name",
"description": "This is the most beautiful ERC20 ever deployed.",
"params": [ // parameter values for the smart contract constructors, this will change depending of your contract
"My token",
"TOKEN",
"1000000000000000000000",
"0x0" // This is the owner and should not be set to 0x0 adress but we do this as this is a tutorial. You should use either the KMS adress or one that you control.
],
"abi": ,// Paste here the abi you copied to clipboard
"bytecode": ,// Paste here the bytecode you copied to clipboard
"compilerVersion": "string",
"signerWallet": "string"
}).then(response => {
console.log(response.data)
})
The smart contract details are returned such as the hash and the address of it.
- From Dashboard, go to Smart Contract.
- Click Deploy from bytecode.
- Enter a name and a description.
- Enter the ABI of your contract.
- Enter the bytecode of your contract.
- Enter the parameters needed.
- Click Deploy.
You can import on Starton smart contracts that are already deployed on the blockchain. To do so, you will need:
- the address and network of the contract
- the ABI of the contract
- From Code
- From Webapp
Be sure to replace x-api-key value
with your own API key!
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/import-existing", {
abi: "[]",
network: "",
description: "",
name: "",
address: "",
})
.then((response) => {
console.log(response.data)
})
Fill up the parameters of the call as follows:
-
ABI (Application Binary Interface): the JSON-formatted interface that defines how to interact with a smart contract's functions and data structures.
-
Network: Specifies the blockchain network (e.g., Ethereum, Binance Smart Chain) where the smart contract is deployed.
-
Description: A brief summary or explanation of the smart contract's purpose and functionality.
-
Name: A string identifier for the smart contractfor easy reference.
-
Address: The unique blockchain address of the smart contract.
- From Dashboard, go to Smart Contract.
- Click + Smart Contract.
- Fill in Smart Contract information:
- Enter your Smart Contract Name
- Select a Blockchain
- Select a Network
- Enter the address.
- Paste your Smart Contract ABI.