Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
sdk.evm
EVM blockchain operations module for Ethereum and compatible chains.
createPublicClient
Create a public client for a specific chain.
try await sdk.evm.createPublicClient(chainId: Int) -> PublicClient
Parameters
- chainId (Int) - Chain ID of the network
Returns
- PublicClient - Public client for the specified chain
Example
let sdk = DynamicSDK.instance()
// Ethereum mainnet
let mainnetClient = try await sdk.evm.createPublicClient(chainId: 1)
// Base Sepolia testnet
let baseSepoliaClient = try await sdk.evm.createPublicClient(chainId: 84532)
// Get gas price
let gasPrice = try await baseSepoliaClient.getGasPrice()
print("Gas price: \(gasPrice.value) wei")
sendTransaction
Send an EVM transaction.
try await sdk.evm.sendTransaction(
transaction: EthereumTransaction,
wallet: BaseWallet
) -> String
Parameters
- transaction (EthereumTransaction) - Transaction to send
- wallet (BaseWallet) - Wallet to send from
Returns
- String - Transaction hash
Example
let sdk = DynamicSDK.instance()
// Get gas price first
let client = try await sdk.evm.createPublicClient(chainId: 84532)
let gasPrice = try await client.getGasPrice()
// Create transaction
let transaction = EthereumTransaction(
from: wallet.address,
to: "0xRecipientAddress...",
value: BigUInt(1000000000000000), // 0.001 ETH in Wei
gas: BigUInt(21000),
maxFeePerGas: gasPrice * 2,
maxPriorityFeePerGas: gasPrice
)
// Send transaction
if let wallet = sdk.wallets.userWallets.first {
let txHash = try await sdk.evm.sendTransaction(
transaction: transaction,
wallet: wallet
)
print("Transaction hash: \(txHash)")
}
signTransaction
Sign a transaction without sending it.
try await sdk.evm.signTransaction(
transaction: EthereumTransaction,
wallet: BaseWallet
) -> String
Parameters
- transaction (EthereumTransaction) - Transaction to sign
- wallet (BaseWallet) - Wallet to sign with
Returns
- String - Signed transaction
Example
import SwiftBigInt
let sdk = DynamicSDK.instance()
if let wallet = sdk.wallets.userWallets.first {
let transaction = EthereumTransaction(
from: wallet.address,
to: "0xRecipientAddress...",
value: BigUInt(1000000000000000),
gas: BigUInt(21000),
maxFeePerGas: BigUInt(20000000000),
maxPriorityFeePerGas: BigUInt(1000000000)
)
let signedTx = try await sdk.evm.signTransaction(
transaction: transaction,
wallet: wallet
)
print("Signed transaction: \(signedTx)")
}
writeContract
Write to a smart contract.
try await sdk.evm.writeContract(
wallet: BaseWallet,
input: WriteContractInput
) -> String
Parameters
- wallet (BaseWallet) - Wallet to send from
- input (WriteContractInput) - Contract call input
Returns
- String - Transaction hash
Example
let sdk = DynamicSDK.instance()
// Parse the built-in ERC-20 ABI
guard let abiData = Erc20.abi.data(using: .utf8),
let abiArray = try JSONSerialization.jsonObject(with: abiData) as? [[String: Any]] else {
throw DynamicSDKError.custom("Invalid Erc20 ABI")
}
// ERC20 transfer
let input = WriteContractInput(
address: "0xTokenContract...",
abi: abiArray,
functionName: "transfer",
args: ["0xRecipient...", "1000000000000000000"]
)
if let wallet = sdk.wallets.userWallets.first {
let txHash = try await sdk.evm.writeContract(wallet: wallet, input: input)
print("Transaction hash: \(txHash)")
}
sdk.networks.evm
Get available EVM networks.
let evmNetworks = sdk.networks.evm // [GenericNetwork]
Example
let sdk = DynamicSDK.instance()
for network in sdk.networks.evm {
print("Network: \(network.name)")
print("Chain ID: \(network.chainId.value)")
}
EthereumTransaction
Transaction object for EVM chains. Requires import SwiftBigInt.
EthereumTransaction(
from: String,
to: String,
value: BigUInt,
gas: BigUInt,
maxFeePerGas: BigUInt,
maxPriorityFeePerGas: BigUInt,
data: String? = nil
)
Properties
| Property | Type | Description |
|---|
from | String | Sender address |
to | String | Recipient address |
value | BigUInt | Amount in Wei |
gas | BigUInt | Gas limit |
maxFeePerGas | BigUInt | Maximum fee per gas |
maxPriorityFeePerGas | BigUInt | Priority fee per gas |
data | String? | Contract call data (optional) |
Input for smart contract interactions. The ABI must be parsed from JSON string to array.
WriteContractInput(
address: String,
abi: [[String: Any]],
functionName: String,
args: [Any]
)
Properties
| Property | Type | Description |
|---|
address | String | Contract address |
abi | [[String: Any]] | Parsed contract ABI (JSON array) |
functionName | String | Function to call |
args | [Any] | Function arguments |
Parsing ABI
// Parse ABI string to array
guard let abiData = abiString.data(using: .utf8),
let abiArray = try JSONSerialization.jsonObject(with: abiData) as? [[String: Any]] else {
throw DynamicSDKError.custom("Invalid ABI format")
}
Complete EVM Example
import DynamicSDKSwift
import SwiftBigInt
let sdk = DynamicSDK.instance()
// Get EVM wallet
guard let wallet = sdk.wallets.userWallets.first(where: {
$0.chain.uppercased() == "EVM"
}) else {
print("No EVM wallet found")
return
}
// Get gas price
let chainId = 84532 // Base Sepolia
let client = sdk.evm.createPublicClient(chainId: chainId)
let gasPrice = try await client.getGasPrice()
// Create and send transaction
let transaction = EthereumTransaction(
from: wallet.address,
to: "0xRecipient...",
value: BigUInt(10000000000000000), // 0.01 ETH
gas: BigUInt(21000),
maxFeePerGas: gasPrice * 2,
maxPriorityFeePerGas: gasPrice
)
let txHash = try await sdk.evm.sendTransaction(
transaction: transaction,
wallet: wallet
)
print("Transaction sent: \(txHash)")
Next Steps