> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gr4vy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating transactions

With the SDK ready, it's time to create a transaction.

## Initialize the SDK

To initialize the SDK, call the `.init()` method on the SDK.

```swift theme={"system"}
import gr4vy_ios

let result = Gr4vy.init(
  gr4vyId: "[GR4VY_ID]",
  token: "[TOKEN]",
  amount: 1299,
  currency: "AUD",
  country: "AU",
  buyerId: nil,
  environment: Gr4vyEnvironment.sandbox
)
```

<Note>
  Replace the `[GR4VY_ID]` with your instance identifier and `[TOKEN]` with the JWT created in step 2.
  Additional [options](/guides/payments/ios/options) can be provided when launching the SDK.
</Note>

<Note>
  The instance ID is the unique identifier for the deployment of the system and is included in every API call.
  Together with the environment (sandbox or production) it is used to connect to the right APIs, as well as dashboard.
</Note>

## Launch & handle events

Next, it's time to open the payment sheet with the `.launch()` method. The launch method requires attaching an event handler
that listens for transactions that have been created or failed, as well as more generic errors.

```swift theme={"system"}
result?.launch(presentingViewController: self, onEvent: { event in
    switch event {
    case .transactionFailed(let transactionID, let status, let paymentMethodID, let responseCode):
        print("Handle a transaction failure, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown"), ResponseCode: \(responseCode ?? "Unknown")")
    case .transactionCreated(let transactionID, let status, let paymentMethodID):
        print("Handle successful transaction, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")")
    case .generalError(let error):
        print("Error: \(error.description)")
    }
})
```

When calling `.launch()` the `presentingViewController` is the current view controller this SDK is launched from.
The SDK presents the payment sheet on top of the current view controller, passing events back to the presenting view controller
via the `onEvent` callback.

<Info>
  Learn more about the events triggered by the iOS SDK in the [events](/guides/payments/ios/events) guide.
</Info>
