Overview

Para Swift SDK provides EVM signing capabilities through the ParaEvmSigner class, enabling you to sign messages, sign transactions, and send transactions on EVM-compatible networks.

Prerequisites

If you haven’t already done so follow the Swift SDK Setup guide to set up the Para Swift SDK before proceeding with this guide.

Usage

Initialize EVM Signer

Create a new instance of ParaEvmSigner by providing your ParaManager instance, RPC URL, and optional wallet ID:

let paraEvmSigner = try! ParaEvmSigner(
    paraManager: paraManager,
    rpcUrl: "https://sepolia.infura.io/v3/<YOUR_API_KEY>",
    walletId: paraManager.wallets.first!.id
)

Select Wallet

You can change the active wallet used for signing at any time:

try! await paraEvmSigner.selectWallet(walletId: paraManager.wallets.first!.id)

Sign Messages

Sign a message using the selected wallet:

let message = "Hello, World!"
let signature = try! await paraEvmSigner.signMessage(message)
print(signature)

Sign Transactions

To sign a transaction without sending it:

  1. Create and encode your transaction
  2. Convert it to base64
  3. Sign using the EVM signer
The swift-sdk provides a Transaction type that can be used to create transactions. You can also use your own transaction type as long as it conforms to the RLP Encodable protocol. Our Transaction type follows a similar structure as the Ethers.js v6 Transaction Type
// Create transaction object
let transaction = Transaction(<TX_PARAMS>)

// Encode transaction
let encodedTransaction = try! JSONEncoder().encode(transaction)
let b64EncodedTransaction = encodedTransaction.base64EncodedString()

// Sign transaction
let txResponse = try! await paraEvmSigner.signTransaction(b64EncodedTransaction)

Send Transactions

To sign and send a transaction in one operation:

// Create and encode transaction
let transaction = Transaction(<TX_PARAMS>)
let encodedTransaction = try! JSONEncoder().encode(transaction)
let b64EncodedTransaction = encodedTransaction.base64EncodedString()

// Send transaction
let signedTx = try! await paraEvmSigner.sendTransaction(b64EncodedTransaction)

Example

Here’s a complete example showing how to initialize the signer and perform various operations:

// Initialize EVM signer
let paraEvmSigner = try! ParaEvmSigner(
    paraManager: paraManager,
    rpcUrl: "https://ethereum-sepolia-rpc.publicnode.com",
    walletId: paraManager.wallets.first!.id
)

// Sign a message
let messageSignature = try! await paraEvmSigner.signMessage("Hello, World!")

// Create and send a transaction
let transaction = Transaction(
    to: "0xRecipientAddress",
    value: 1000000000000000000,
    gasLimit: 21000,
    gasPrice: 20000000000
)

let encodedTransaction = try! JSONEncoder().encode(transaction)
let b64EncodedTransaction = encodedTransaction.base64EncodedString()
let txResult = try! await paraEvmSigner.sendTransaction(b64EncodedTransaction)

Do not pass in hex values for the transaction parameters. The SDK will automatically convert them to hex. Values are assumed to be in wei by default.

Example

For an active example swift project, check out: