{"id":28425274,"url":"https://github.com/metamask/metamask-ios-sdk","last_synced_at":"2025-06-26T04:31:12.226Z","repository":{"id":99880175,"uuid":"558339768","full_name":"MetaMask/metamask-ios-sdk","owner":"MetaMask","description":"MetaMask SDK for iOS","archived":false,"fork":false,"pushed_at":"2024-10-02T08:02:56.000Z","size":80252,"stargazers_count":46,"open_issues_count":3,"forks_count":44,"subscribers_count":67,"default_branch":"main","last_synced_at":"2025-06-05T10:50:29.688Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MetaMask.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":null,"patreon":null,"open_collective":"metamask","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2022-10-27T10:59:54.000Z","updated_at":"2025-05-24T12:17:56.000Z","dependencies_parsed_at":"2024-01-18T12:45:23.295Z","dependency_job_id":"328197ad-bb40-49eb-a0cc-80c77673ccc3","html_url":"https://github.com/MetaMask/metamask-ios-sdk","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/MetaMask/metamask-ios-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fmetamask-ios-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fmetamask-ios-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fmetamask-ios-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fmetamask-ios-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MetaMask","download_url":"https://codeload.github.com/MetaMask/metamask-ios-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fmetamask-ios-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262001301,"owners_count":23243041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-05T10:36:47.978Z","updated_at":"2025-06-26T04:31:12.215Z","avatar_url":"https://github.com/MetaMask.png","language":"Swift","funding_links":["https://opencollective.com/metamask"],"categories":[],"sub_categories":[],"readme":"# MetaMask iOS SDK\n\nImport MetaMask SDK into your native iOS dapp to enable your users to easily connect with their\nMetaMask Mobile wallet.\n\nSee the [example iOS dapp](Example) and the documentation for\n[setting up the SDK in your iOS dapp](https://docs.metamask.io/wallet/how-to/connect/set-up-sdk/mobile/ios/)\nfor more information.\n\nYou can also see the [JavaScript SDK repository](https://github.com/MetaMask/metamask-sdk) and the\n[Android SDK repository](https://github.com/MetaMask/metamask-android-sdk).\n\n## Prerequisites\n\n- MetaMask Mobile version 7.6.0 or later installed on your target device (that is, a physical device\n  or emulator).\n  You can install MetaMask Mobile from the [App Store](https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202)\n  or clone and compile MetaMask Mobile from [source](https://github.com/MetaMask/metamask-mobile)\n  and build to your target device. Deeplink communication is only available from MetaMask Wallet version 7.21.0\n\n- iOS version 15 or later.\n  The SDK supports `ios-arm64` (iOS devices) and `ios-arm64-simulator` (M1 chip simulators).\n  It currently doesn't support `ios-ax86_64-simulator` (Intel chip simulators).\n  \n  - Swift 5.5 or later.\n\n## Get started\n\n### 1. Install the SDK\n\n#### CocoaPods\n\nTo add the SDK as a CocoaPods dependency to your project, add the following entry to our Podfile:\n\n```text\npod 'metamask-ios-sdk'\n```\n\nRun the following command:\n\n```bash\npod install\n```\n\n#### Swift Package Manager\n\nTo add the SDK as a Swift Package Manager (SPM) package to your project, in Xcode, select\n**File \u003e Swift Packages \u003e Add Package Dependency**.\nEnter the URL of the MetaMask iOS SDK repository: `https://github.com/MetaMask/metamask-ios-sdk`.\n\nAlternatively, you can add the URL directly in your project's package file:\n\n```swift\ndependencies: [\n    .package(\n        url: \"https://github.com/MetaMask/metamask-ios-sdk\",\n        from: \"0.8.10\"\n    )\n]\n```\n\n### 2. Import the SDK\n\nImport the SDK by adding the following line to the top of your project file:\n\n```swift\nimport metamask_ios_sdk\n```\n\n### 3. Connect your dapp\n\nWe have provided a convenient way to make rpc requests without having to first make a connect request. Please refer to [Connect With Request](#5-connect-with-request) for examples. Otherwise you can connect your dapp to MetaMask as follows:\n\nCreate dapp metadata\n```swift\nlet appMetadata = AppMetadata(name: \"Dub Dapp\", url: \"https://dubdapp.com\")\n```\n\n#### Option 1: Deeplink Communication Layer\nThe SDK supports communication with MetaMask wallet via deeplinking. To configure your dapp to work with deeplink communication you need to add a url scheme in your dapp target's Info setting under URL Types. Alternatively you can add it in your dapp's plist as shown below:\n```\n    \u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n    \u003carray\u003e\n        \u003cdict\u003e\n            \u003ckey\u003eCFBundleTypeRole\u003c/key\u003e\n            \u003cstring\u003eEditor\u003c/string\u003e\n            \u003ckey\u003eCFBundleURLName\u003c/key\u003e\n            \u003cstring\u003ecom.dubdapp\u003c/string\u003e\n            \u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n            \u003carray\u003e\n                \u003cstring\u003edubdapp\u003c/string\u003e\n            \u003c/array\u003e\n        \u003c/dict\u003e\n    \u003c/array\u003e\n```\nThen in the AppDelegate's open url method handle deeplinks from the MetaMask wallet\n```swift\nfunc application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n    if URLComponents(url: url, resolvingAgainstBaseURL: true)?.host == \"mmsdk\" {\n        MetaMaskSDK.sharedInstance?.handleUrl(url)\n    } else {\n        // handle other deeplinks\n    }\n    return true\n}\n```\nAnd then initialise the SDK, specifying `.deeplinking` as the transport type, passing the dapp's' scheme you added in the URL Types as the `dappScheme`. To use the Infura API to make read-only requests, specify your Infura API key using the `infuraAPIKey` option in `SDKOptions`. To use your own node (for example, with Hardhat) to make read-only requests, specify your node's chain ID and RPC URL using the readonlyRPCMap option.\n```swift\n@ObservedObject var metamaskSDK = MetaMaskSDK.shared(\n    appMetadata,\n    transport: .deeplinking(dappScheme: \"dubdapp\"),\n    sdkOptions: SDKOptions(infuraAPIKey: \"your-api-key\", readonlyRPCMap: [\"0x1\": \"hptts://www.testrpc.com\"]) // for read-only RPC calls\n)\n```\n#### NOTE\nNote that deeplink communication is only available from MetaMask Wallet version 7.21.0.\n\n#### Option 2: Socket Communication Layer\nAlternatively, by default, the dapp communicates with the MetaMask wallet via sockets.\n```swift\n// To use deeplinking as transport layer\n@ObservedObject var metamaskSDK = MetaMaskSDK.shared(\n    appMetadata,\n    transport: .socket,\n    sdkOptions: SDKOptions(infuraAPIKey: \"your-api-key\") // for read-only RPC calls\n```\nThen connect the SDK\n```swift\nlet connectResult = await metamaskSDK.connect()\n```\n\nBy default, MetaMask logs three SDK events: `connectionRequest`, `connected`, and `disconnected`.\nThis allows MetaMask to monitor any SDK connection issues.\nTo disable this, set `metamaskSDK.enableDebug = false`.\n\n### 4. Call methods\n\nYou can now call any [JSON-RPC API method](https://docs.metamask.io/wallet/reference/eth_subscribe/)\nusing `metamaskSDK.request()`.\n\nWe have provided convenience methods for most common rpc calls so that you do not have to manually construct rpc requests. However, if you wish to provide a more fine-grained request not catered for by the convenience methods you can construct a request and then call `metamaskSDK.request(EthereumRequest)`\n\n#### Example: Get chain ID\n\nThe following example gets the user's chain ID by calling\n[`eth_chainId`](https://docs.metamask.io/wallet/reference/eth_chainid/).\n\n```swift\nlet result = await metamaskSDK.getChainId()\n```\n\n#### Example: Get account balance\n\nThe following example gets the user's account balance by calling\n[`eth_getBalance`](https://docs.metamask.io/wallet/reference/eth_getbalance/).\n\n```swift\n\n// Create parameters\nlet selectedAddress = metamaskSDK.account\n\n// Make request\nlet accountBalance = await metamaskSDK.getEthBalance(address: selectedAddress, block: \"latest\")\n```\n\n#### Example: Send transaction\n\nThe following example sends a transaction by calling\n[`eth_sendTransaction`](https://docs.metamask.io/wallet/reference/eth_sendtransaction/).\n\n**Use convenience method**\n```swift\nlet selectedAddress = metamaskSDK.account\n\nlet result = await metamaskSDK.sendTransaction(\n    from: selectedAddress, \n    to: \"0x...\", // recipient address\n    value: \"0x.....\" // amount\n    )\n```\n\n**Use a dictionary**\n\nIf your request parameters make up a simple dictionary of string key-value pairs, you can use the\ndictionary directly.\nNote that `Any` or even `AnyHashable` types aren't supported, since the type must be explicitly known.\n\n```swift\n// Create parameters\nlet account = metamaskSDK.account\n\nlet parameters: [String: String] = [\n    \"to\": \"0x...\", // receiver address\n    \"from\": account, // sender address\n    \"value\": \"0x...\" // amount\n  ]\n\n// Create request\nlet transactionRequest = EthereumRequest(\n    method: .ethSendTransaction,\n    params: [parameters] // eth_sendTransaction expects an array parameters object\n    )\n\n// Make a transaction request\nlet transactionResult = await metamaskSDK.request(transactionRequest)\n```\n\n**Use a struct**\n\nFor more complex parameter representations, define and use a struct that conforms to `CodableData`,\nthat is, a struct that implements the following requirement:\n\n```\nfunc socketRepresentation() -\u003e NetworkData\n```\n\nThe type can then be represented as a socket packet.\n\n```swift\nstruct Transaction: CodableData {\n    let to: String\n    let from: String\n    let value: String\n    let data: String?\n\n    init(to: String, from: String, value: String, data: String? = nil) {\n        self.to = to\n        self.from = from\n        self.value = value\n        self.data = data\n    }\n\n    func socketRepresentation() -\u003e NetworkData {\n        [\n            \"to\": to,\n            \"from\": from,\n            \"value\": value,\n            \"data\": data\n        ]\n    }\n}\n\n// Create parameters\nlet account = metamaskSDK.account\n\nlet transaction = Transaction(\n    to: \"0x...\", // receiver address\n    from: account, // sender address\n    value: \"0x...\" // amount\n)\n\n// Create request\nlet transactionRequest = EthereumRequest(\n    method: .ethSendTransaction,\n    params: [transaction] // eth_sendTransaction expects an array parameters object\n    )\n\n// Make a transaction request\nlet result = await metamaskSDK.request(transactionRequest)\n```\n#### Example: Send chained rpc (batch) requests\n```swift\n\nPlease note that for request batching, the collection of `EthereumRequest\u003cT\u003e` needs to be of the same `\u003cT\u003e` type, i.e all requests use the same `params` type, e.g `[Transaction]`, or `[String]` etc. You can mix the rpc requests e.g a mix of `personal_sign`, eth_signTypedData_v4 etc as long as they share the same params type. \n// Create parameters\nlet account = metamaskSDK.account\n\nlet params1: [String] = [account, \"Message 1\"]\nlet params2: [String] = [account, \"Message 2\"]\nlet params3: [String] = [account, \"Message 3\"]\n\nlet signRequest1 = EthereumRequest(\n    method: .personalSign,\n    params: params1\n)\n\nlet signRequest2 = EthereumRequest(\n    method: .personalSign,\n    params: params2\n)\n\nlet signRequest3 = EthereumRequest(\n    method: .personalSign,\n    params: params3\n)\n\nlet requestBatch: [EthereumRequest] = [signRequest1, signRequest2, signRequest3]\n\nlet result = await metamaskSDK.batchRequest(requestBatch)\n```\n\n### 5. Connect With Request\n#### Example: Connect with request\n\nWe have provided a convenience method that enables you to connect and make any request in one rpc request without having to call `connect()` first.\n\n```swift\nlet transaction = Transaction(\n    to: to,\n    from: metamaskSDK.account, // this is initially empty before connection, will be populated with selected address once connected\n    value: amount\n)\n\nlet parameters: [Transaction] = [transaction]\n\nlet transactionRequest = EthereumRequest(\n    method: .ethSendTransaction,\n    params: parameters\n)\n\nlet transactionResult = metamaskSDK.connectWith(transactionRequest)\n```\n\n#### Example: Connect with sign\n\nWe have further provided a specific convenience method that enables you to connect and make a personal sign rpc request.\nIn this case you do not need to construct a request, you only provide the message to personal sign.\n\n```kotlin\nval message = \"This is the message to sign\"\n\nlet connectSignResult = await metamaskSDK.connectAndSign(message: message)\n\nswitch connectSignResult {\n    case let .success(value):\n        // use result\n    case let .failure(error):\n        // handle error\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetamask%2Fmetamask-ios-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetamask%2Fmetamask-ios-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetamask%2Fmetamask-ios-sdk/lists"}