Transaction Flow

Create and sign a transaction using the SDK and the customer backend application.

  1. Typically, a transaction would be initiated by a user taking some action in your application. This could be the user initiating a transfer of tokens, or interacting with a DApp through the WalletConnect integration. This part is specific to your application.
  2. From your backend, use a Create Transaction API call to create a new transaction. In your request, you will need to set the vault_id of the origin vault of the transaction as well as the full details of the transaction (see examples). Furthermore, for all WaaS transactions, you need to set the signer_type field in the request to end_user. As always, your backend will need to authenticate by passing its API User token. The response of this call will include the transaction ID of the newly created transaction. To sign this transaction, you need to pass the transaction ID to your client-side application.
  3. From your client-side application, user the signTransaction SDK function to sign the transaction. As input, this function takes the transaction ID that your backend application received when it created the transaction in the previous step. See example code, below:
async function appSignTransaction() {
  try {
    await signTransaction('my-transaction-id'); // transaction id to sign
  } catch (e) {
    const error = e as FordefiSdkErrorResult;
    console.log(
      `there was an error. error code :${error.code}, error message: ${error.message}`
    );
  }
}
import com.fordefi.fordefi.Fordefi
import com.fordefi.fordefi.FordefiError

class MainActivity: ComponentActivity() {
  private
  var fordefi: Fordefi ? = null
  private val transactionID = "<TRANSACTION_ID>"

  override fun onCreate(savedInstanceState: Bundle ? ) {
    super.onCreate(savedInstanceState)
      ...
      fordefi!!.signTransaction(transactionID) {
        error: FordefiError ? ->
          handleSignTransaction(transactionID, error)
      }
  }

  private fun handleSignTransaction(transactionID: String, error: FordefiError ? ) {
    if (error == null) {
      Log.i("FordefiSDK",
        "Trasaction $transactionID was signed successfully"
      )
    } else {
      Log.i("FordefiSDK",
        String.format(
          "Failed to sign transaction with id: $transactionID. Error: %s",
          error.description()
        )
      )
    }
  }
}
import FordefiSdk

class ViewController: UIViewController {
  private var fordefi: Fordefi?
  private var transactionID = "<TRANSACTION_ID>"
  override func viewDidAppear(_ animated: Bool) {
    ///...
    self.fordefi?.signTransaction(
      transactionID: self.transactionID,
      completionHandler: { error in
        self.handleSignTransaction(error: error)
      })
  }

  private func handleSignTransaction(error: FordefiError?) {
    if error != nil {
      print("Sign Transaction failed. Error: \(error!.errorDescription!)")
    }
  }
}

await fordefi.signTransaction(transactionId);

  1. Once signed, the signed transaction will be pushed to the blockchain by Fordefi. Your backend application will receive webhook notifications upon the completion of the transaction (as well as on several intermediate state changes).

📘

More about transactions

The Programmatic Transactions section of this developer guide contains various advanced topics about creating and managing transactions with our API, such as Transaction Simulation, Monitoring Transactions, Releasing Stuck EVM Transactions, and many more.