Skip to main content

Creating a transaction

You can create a transaction from Code with Starton. The transaction endpoint is at the root of several other endpoints of Starton API, such as smart contract.

Here you can create a simple transaction. For all advanced parameters, check the Transaction section of our API reference.

const axios = require("axios")

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

startonAPI
.post("/v3/transaction", {
network: "polygon-amoy",
signerWallet: "0x694F07CEEc0869aa0dB5E8157FA538268F28B23f",
from: "0x694F07CEEc0869aa0dB5E8157FA538268F28B23f",
to: "0x6d86C7046CCfA2022BFcad18F0C993B55e1512dE",
value: "100", // in wei.
})
.then((res) => console.log(res.data))
.catch((e) => console.log(e))

This request includes the required parameters, you can also specify the following:

  • speed: Maximum amount of gas to be consumed in a transaction. Options are 'low', 'average, 'fast', 'fastest' or 'custom'. If custom, the customGas field is required.
    • customGas: Used when gasLimit is set to custom. It specifies the exact gas limit.
      • maxFeePerGas: Maximum total fee per unit of gas, including base and priority fees. Used in EIP-1559 transactions.
      • maxPriorityFeePerGas: Maximum tip per unit of gas to incentivize miners. Paid over the base fee in EIP-1559 transactions.
      • gasPrice: Fee per unit of gas for non-EIP-1559 transactions.
  • network: The blockchain network for the transaction (see supported networks).
  • nonce: Unique number for each transaction. The nonce is optional and auto-assigned if not provided. Otherwise, the nonce allows ordering of the transactions. The value of nonce must cannot be random. In case of an invalid nonce, the transaction will be refused. See Nonces
  • signerWallet: Address of the wallet initiating the transaction. You can use a wallet from your Key Management System or create a test wallet. See Wallets
  • to: Recipient's address.
  • value: Amount of currency to transfer, in wei for Ethereum-based networks.
  • data: Payload or data of the transaction.
  • metadata: Additional information about the transaction for record-keeping.

info

If you want to modify a pending transaction, you can send a new transaction with the same nonce as the transaction you want to modify. This will overwrite the previous transaction. You can also do this if you want to cancel a pending transaction. You can do the same with erroneous information in your transaction. For example, you can put an invalid signature. Don't forget to put the same nonce as the queued transaction you want to cancel.