Skip to content

Prepare a Transaction and Submit it across Different Contract Types

To prepare and submit a transaction across different contract types, you can follow these general steps:

Initialize the Contract:

Depending on the contract type, initialize the contract using the appropriate provider or signer. For example, for a TradeTokenContract, you can initialize it as follows:

javascript
import { TradeTokenContract } from "skc-sdk";
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
const signer = provider.getSigner();
const tradeToken = new TradeTokenContract("0xYourTradeTokenContractAddress", provider, "http://localhost:8545");
// or using signer
const tradeToken = new TradeTokenContract("0xYourTradeTokenContractAddress", signer, "http://localhost:8545");

Prepare Transaction Data:

Use the prepareTxData method to prepare the transaction data for a specific method in the contract. For example, for a SalesOrderContract:

javascript
import { SalesOrderContract } from 'skc-sdk';
const salesOrderContract = new SalesOrderContract("0xSalesOrderContractAddress", provider, "http://localhost:8545");
const txData = await salesOrderContract.prepareTxData(
  "createOrder",
  ["0xSellerAddress", "BaseToken", "QuoteToken", 1000],
  "0xSignerAddress",
  "Creating sales order"
);

Sign the Transaction:

Depending on the signing method (CMS, Vault, or AWS), sign the prepared transaction. For example, using CMS:

javascript
import { TradeCms } from "skc-trade-sdk";
const cms = new TradeCms("https://example.com");
const signedTx = await cms.signTx(txData);

Submit the Transaction:

Finally, submit the signed transaction using the submitTx method. For example:

javascript
const submit = await cms.submitTx(signedTx);

Example for Different Contract Types

  • Trade Token Contract:

    javascript
    import { TradeTokenContract } from "skc-sdk";
    const tradeToken = new TradeTokenContract("0xYourTradeTokenContractAddress", provider, "http://localhost:8545");
    const txData = await tradeToken.prepareTxData("methodName", ["arg1", "arg2"], "0xSignerAddress", "Optional memo");
    const signedTx = await cms.signTx(txData);
    const submit = await cms.submitTx(signedTx);
  • Sales Order Contract:

    javascript
    import { SalesOrderContract } from 'skc-sdk';
    const salesOrderContract = new SalesOrderContract("0xSalesOrderContractAddress", provider, "http://localhost:8545");
    const txData = await salesOrderContract.prepareTxData("createOrder", ["0xSellerAddress", "BaseToken", "QuoteToken", 1000], "0xSignerAddress", "Creating sales order");
    const signedTx = await cms.signTx(txData);
    const submit = await cms.submitTx(signedTx);
  • Payment Commitment Contract:

    javascript
    import { PaymentCommitmentContract } from 'skc-sdk';
    const paymentCommitment = new PaymentCommitmentContract("0xContractAddress", provider, "rpc-url");
    const txData = await paymentCommitment.prepareTxData("methodName", ["arg1", "arg2"], "0xSignerAddress", "Optional memo");
    const signedTx = await cms.signTx(txData);
    const submit = await cms.submitTx(signedTx);

Signing Options

  • CMS Signing Option:

    javascript
    import { TradeCms } from "skc-trade-sdk";
    const cms = new TradeCms("https://example.com");
    const signedTx = await cms.signTx(txData);
  • Vault Signing Option:

    javascript
    import { SkcVault } from "skc-sdk";
    const vault = new SkcVault({ pluginPath: "/path/to/plugin", vaultAddress: "http://vault.example.com", vaultToken: "vault-token" }, "offset");
    const vaultSignedTx = await vault.signTransaction({ from: "0xYourAddress", to: "0xRecipientAddress", data: "Encrypted data", nonce: "0", gasLimit: "100000", chainId: "31337" });
  • AWS Signing Option:

    javascript
    import { SkcAws } from "skc-sdk";
    const awsConfig = { apiId: "api-id", stage: "prod", region: "aws-region", secretId: "secret-id", credentials: { accessKeyId: "access-key", secretAccessKey: "secret-key" } };
    const aws = new SkcAws(awsConfig, "offset", "message encoded or not");
    const signedAwsTx = await aws.signTransaction({ from: "0xYourAddress", to: "0xRecipientAddress", data: "Encrypted data", nonce: "0", gasLimit: "100000", chainId: "31337" });

By following these steps, you can prepare and submit transactions across different contract types using various signing options.