Skip to content

Latest commit

 

History

History
564 lines (420 loc) · 56 KB

File metadata and controls

564 lines (420 loc) · 56 KB

SmartContractManagement

(smartContractManagement)

Overview

The Smart contract management is an abstraction on top of our Transaction Manager and it allow you to build and automate your smart contract transaction easily, without struggling with the ABI and params encoding. With it you can:

  • Deploying smart contract: Deploy audited contract from our library or your own smart contract
  • Import existing contract: Import existing contract to view them on your dashboard and interact with them.
  • Interact: Read state and interact with the smart contract previously deployed or imported

Available Operations

call

Calls a specific function within a deployed smart contract, enabling interactions such as executing transactions or querying state. The method parameters, including the smart contract address and network, need to be specified.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.call({
    callDto: {
      functionName: "<value>",
      params: [
        "TestToken",
        "TEST",
        "1000000000000000000000000",
        "0x298e760768c8481780397eE28A127eAd584df4ee",
      ],
      signerWallet: "<value>",
    },
    address: "0x820f8728E32519b9C91B2406BF48AF80711aFecD",
    network: "polygon-mumbai",
    simulate: false,
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.CallSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.CallSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.CallSmartContractResponseBody 400 application/json
errors.CallSmartContractSmartContractManagementResponseBody 404 application/json
errors.CallSmartContractSmartContractManagementResponseResponseBody 422 application/json
errors.CallSmartContractSmartContractManagementResponse500ResponseBody 500 application/json
errors.SDKError 4xx-5xx /

delete

Deletes a specific smart contract based on network and address.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.delete({
    address: "8653 Vaughn Hills",
    network: "polygon-mumbai",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.DeleteSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.DeleteSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.DeleteSmartContractResponseBody 400 application/json
errors.DeleteSmartContractSmartContractManagementResponseBody 404 application/json
errors.SDKError 4xx-5xx /

deployFromBytecode

Deploys a smart contract from bytecode and returns transaction details.

Example Usage

import { Starton } from "@starton/sdk";
import { Type } from "@starton/sdk/sdk/models/shared";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.deployFromBytecode({
    deployFromBytecodeDto: {
      abi: [
        {
          type: Type.Event,
        },
      ],
      bytecode: "<value>",
      name: "<value>",
      network: "<value>",
      params: [
        "TestToken",
        "TEST",
        "1000000000000000000000000",
        "0x298e760768c8481780397eE28A127eAd584df4ee",
      ],
      signerWallet: "<value>",
    },
    simulate: false,
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.DeployFromBytecodeSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.DeployFromBytecodeSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.DeployFromBytecodeSmartContractResponseBody 400 application/json
errors.DeployFromBytecodeSmartContractSmartContractManagementResponseBody 404 application/json
errors.DeployFromBytecodeSmartContractSmartContractManagementResponseResponseBody 422 application/json
errors.DeployFromBytecodeSmartContractSmartContractManagementResponse500ResponseBody 500 application/json
errors.SDKError 4xx-5xx /

deployFromTemplate

Deploy from Starton audited smart contract template.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.deployFromTemplate({
    deployFromTemplateDto: {
      name: "TestToken",
      network: "polygon-mumbai",
      params: [
        "TestToken",
        "TEST",
        "1000000000000000000000000",
        "0x298e760768c8481780397eE28A127eAd584df4ee",
      ],
      signerWallet: "0x298e760768c8481780397eE28A127eAd584df4ee",
      templateId: "ERC20_META_TRANSACTION",
    },
    simulate: false,
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.DeployFromTemplateSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.DeployFromTemplateSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.DeployFromTemplateSmartContractResponseBody 400 application/json
errors.DeployFromTemplateSmartContractSmartContractManagementResponseBody 404 application/json
errors.DeployFromTemplateSmartContractSmartContractManagementResponseResponseBody 500 application/json
errors.SDKError 4xx-5xx /

getAll

Fetches and returns the list of smart contracts.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.getAll({
    address: "0x820f8728E32519b9C91B2406BF48AF80711aFecD",
    includeAbi: true,
    includeCompilationDetails: true,
    limit: 20,
    network: "polygon-mumbai",
    page: 0,
  });

  for await (const page of result) {
    // handle page
  }
}

run();

Parameters

Parameter Type Required Description
request operations.GetAllSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetAllSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.GetAllSmartContractResponseBody 400 application/json
errors.SDKError 4xx-5xx /

getFunctions

Provides a list of the available read and write functions, as well as events, of a specified smart contract. This can be used to understand how to interact with the contract.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.getFunctions({
    address: "0x820f8728E32519b9C91B2406BF48AF80711aFecD",
    network: "polygon-mumbai",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.GetAvailableFunctionsSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetAvailableFunctionsSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.GetAvailableFunctionsSmartContractResponseBody 400 application/json
errors.GetAvailableFunctionsSmartContractSmartContractManagementResponseBody 404 application/json
errors.GetAvailableFunctionsSmartContractSmartContractManagementResponseResponseBody 500 application/json
errors.SDKError 4xx-5xx /

getOne

Fetches details of a specific smart contract based on network and address.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.getOne({
    address: "0x820f8728E32519b9C91B2406BF48AF80711aFecD",
    includeAbi: true,
    includeCompilationDetails: true,
    network: "polygon-mumbai",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.GetOneSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.GetOneSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.GetOneSmartContractResponseBody 400 application/json
errors.GetOneSmartContractSmartContractManagementResponseBody 404 application/json
errors.SDKError 4xx-5xx /

importExisting

Import an already deployed smart contract into the project. This requires providing the smart contract’s address, ABI, and the network it’s deployed on.

Example Usage

import { Starton } from "@starton/sdk";
import { StateMutability, Type } from "@starton/sdk/sdk/models/shared";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.importExisting({
    abi: [
      {
        inputs: {
          name: "<value>",
          type: "<value>",
        },
        stateMutability: StateMutability.Nonpayable,
        type: Type.Constructor,
      },
    ],
    address: "0x1C1f7A4d7F853856b964947CA03B92993D3ef40e",
    creationHash: "0x55b782a3db6d7b8c1949536110dcaaac69b4f83455959ab2839c09c2ed2ab1da",
    description: "Test minimal contract tests.",
    name: "Minimal contract tests.",
    network: "polygon-mumbai",
    params: [
      "TestToken",
      "TEST",
      "1000000000000000000000000",
      "0x298e760768c8481780397eE28A127eAd584df4ee",
    ],
    templateId: "ERC721_META_TRANSACTION",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request shared.ImportSmartContractDto ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.ImportExistingSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.ImportExistingSmartContractResponseBody 400 application/json
errors.SDKError 4xx-5xx /

read

Reads data from a smart contract by calling one of its functions without making any state changes on the blockchain. This is typically used for retrieving information from the contract.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.read({
    readDto: {
      functionName: "<value>",
      params: [
        "TestToken",
        "TEST",
        "1000000000000000000000000",
        "0x298e760768c8481780397eE28A127eAd584df4ee",
      ],
    },
    address: "0x820f8728E32519b9C91B2406BF48AF80711aFecD",
    network: "polygon-mumbai",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.ReadSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.ReadSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.ReadSmartContractResponseBody 400 application/json
errors.ReadSmartContractSmartContractManagementResponseBody 404 application/json
errors.ReadSmartContractSmartContractManagementResponseResponseBody 500 application/json
errors.SDKError 4xx-5xx /

update

Updates and returns details of a specific smart contract based on network and address.

Example Usage

import { Starton } from "@starton/sdk";

const starton = new Starton({
  startonApiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await starton.smartContractManagement.update({
    updateSmartContractDto: {},
    address: "0x820f8728E32519b9C91B2406BF48AF80711aFecD",
    network: "polygon-mumbai",
  });

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.UpdateSmartContractRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.

Response

Promise<operations.UpdateSmartContractResponse>

Errors

Error Object Status Code Content Type
errors.UpdateSmartContractResponseBody 400 application/json
errors.UpdateSmartContractSmartContractManagementResponseBody 404 application/json
errors.SDKError 4xx-5xx /