Execute Transaction

executeTx is a high level method of Deployer which can be used to perform transactions on Algorand Network. It supports every transaction (atomic or single) which is possible in network. Ex: Deploy ASA/App, Opt-In, Transfers, Delete, Destroy etc. executeTx takes ExecParams[] as parameter. If the length of ExecParams array is greater than one, it will be considered as atomic transaction. In below sections we will demonstrate how to pass these parameters.

Note: For each parameter type and sign fields are mandatory.

  • type: type of transaction
  • sign: sign type

Examples of parameter ExecParams:

Transfer Algo using secret key

  {
    type: TransactionType.TransferAlgo,
    sign: SignType.SecretKey,
    fromAccount: john,
    toAccountAddr: alice.address,
    amountMicroAlgos: 100,
    payFlags: { totalFee: fee }  }

Transfer Algo using logic signature

  {
    type: TransactionType.TransferAlgo,
    sign: SignType.LogicSignature,
    fromAccountAddr: contractAddress,
    toAccountAddr: alice.address,
    amountMicroAlgos: 100,
    lsig: lsig,
    payFlags: { totalFee: fee }
  }

Deploy ASA

To deploy an ASA using asa.yaml:

  {
    type: TransactionType.DeployASA,
    sign: SignType.SecretKey,
    fromAccount: john,
    asaName: 'gold',
    payFlags: { totalFee: fee }
  }

To deploy an ASA without using asa.yaml:

  {
    type: types.TransactionType.DeployASA,
    sign: types.SignType.SecretKey,
    fromAccount: john.account,
    asaName: 'silver-12',
    asaDef: {
      total: 10000,
      decimals: 0,
      defaultFrozen: false,
      unitName: "SLV",
      url: "url",
      metadataHash: "12312442142141241244444411111133",
      note: "note"
    },
    payFlags: {}
  };

Opt-In to ASA

  {
    type: TransactionType.OptInASA,
    sign: SignType.SecretKey,
    fromAccount: alice,
    assetID: assetIndex,
    payFlags: { totalFee: fee }
  }

Transfer Asset

  {
    type: TransactionType.TransferAsset,
    sign: SignType.SecretKey,
    fromAccount: john,
    toAccountAddr: alice.address,
    amount: 10,
    assetID: assetId,
    payFlags: { totalFee: fee }
  }

Deploy App

We support 3 format of DeloyApp params:

  • Deploy source from files(supported in algob cli and runtime).
    {
      type: TransactionType.DeployApp,
      sign: SignType.SecretKey,
      fromAccount: john,
      appDefinition: {
        appName: "my-app",
        metaTypes: MetaType.File
        approvalProgramFilename: "approval.teal",
        clearProgramFileName: "clear.teal",
        localInts: 1,
        localBytes: 1,
        globalInts: 1,
        globalBytes: 1,
      }
      payFlags: {}
    }
    
    • Deploy source from code(supported in algob cli and runtime).
      {
      type: TransactionType.DeployApp,
      sign: SignType.SecretKey,
      fromAccount: john,
      appDefinition: {
        appName: "my-app",
        metaTypes: MetaType.SOURCE_CODE
        approvalProgramCode: "<approval program>",
        clearProgramCode: "<clear state program>",
        localInts: 1,
        localBytes: 1,
        globalInts: 1,
        globalBytes: 1,
      }
      payFlags: {}
      }
      
  • Deploy source from compiled code(supported in algob cli and web).
  {
    type: TransactionType.DeployApp,
    sign: SignType.SecretKey,
    fromAccount: john,
    appDefinition: {
      appName: "my-app",
      metaTypes: MetaType.BYTES
      approvalProgramBytes: "<compiled bytes from algod client>",
      clearProgramBytes: "<compiled bytes from algod client>",
      localInts: 1,
      localBytes: 1,
      globalInts: 1,
      globalBytes: 1,
    }
    payFlags: {}
  }
  • To learn about more parameters like (account, appArgs, ForeignApps, ForeignAssets etc).Please check AppOptionalFlags

Opt-In to App

  {
    type: TransactionType.OptInToApp,
    sign: SignType.SecretKey,
    fromAccount: alice,
    appID: appID,
    payFlags: { totalFee: fee }
  }

Call App

  {
    type: TransactionType.CallNoOpApp,
    sign: SignType.SecretKey,
    fromAccount: john,
    appId: 0,
    payFlags: { totalFee: fee }
  }

Update App

newAppCode type is SmartContract. Please check types define.

  {
    type: TransactionType.UpdateApp,
    sign: SignType.SecretKey,
    fromAccount: john,
    appID: appId,
    appName: "my-app",
    newAppCode: {
      metaTypes: MetaType.File
      approvalProgramFilename: "approval.teal",
      clearProgramFileName: "clear.teal", 
    }, 
    payFlags: {}
  }

Delete App

  {
    type: TransactionType.DeleteApp,
    sign: SignType.SecretKey,
    fromAccount: john,
    appId: 10,
    payFlags: { totalFee: fee },
    appArgs: []
  }

Pooled Transaction Fees

With this release, algob also supports pooled transaction fees. Algob now supports pooled fees where one transaction can pay the fees of other transactions within an atomic group. For atomic transactions, the protocol sums the number of transactions and calculates the total amount of required fees, then calculates the amount of fees submitted by all transactions. If the collected fees are greater than or equal to the required amount, the transaction fee requirement will be met. Ex:

  {
    type: TransactionType.TransferAlgo,
    sign: SignType.SecretKey,
    fromAccountAddr: john,
    toAccountAddr: alice.address,
    amountMicroAlgos: 100,
    payFlags: { totalFee: 2000 }
  },
  {
    type: TransactionType.TransferAlgo,
    sign: SignType.SecretKey,
    fromAccountAddr: alice,
    toAccountAddr: bob.address,
    amountMicroAlgos: 100,
    payFlags: { totalFee: 0 }
  }

Even though fee paid by alice is 0, this transaction will pass because total fees collected is greater than or equal to the required amount.

Sign and Send SDK Transaction object using executeTx method

deployer.executeTx method supports signing and sending sdk transaction objects. To do this you will have to pass an TransactionAndSign object which has transaction and sign. Ex:

const tx = makeAssetCreateTxn(
  bobAcc.addr, mockSuggestedParam.fee,
  mockSuggestedParam.firstRound, mockSuggestedParam.lastRound,
  undefined, mockSuggestedParam.genesisHash, mockSuggestedParam.genesisID,
  1e6, 0, false, undefined, undefined, undefined, undefined, "UM", "ASM", undefined
);
const transaction: wtypes.TransactionAndSign = {
  transaction: tx,
  sign: {sign: wtypes.SignType.SecretKey, fromAccount: bobAcc}
}

const res = await deployer.executeTx([transaction]);

You can check the implementation in asa example.

SignTransactions function

This function takes array of TransactionAndSign objects and returns raw signed transaction

const transaction: wtypes.TransactionAndSign = [{
  transaction: SDKTx,
  sign: {sign: wtypes.SignType.SecretKey, fromAccount: bobAcc}
}]
const rawSign = signTransactions(transaction)

rawSign has array of raw signed transactions. You can check the implementation in asa example.