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

# Members and Roles

> Administer who can manage a business account from Swift, and transfer ownership.

<Note>
  Business Accounts are in **early access**. See the [overview](/docs/swift/business-accounts/overview) for the model.
</Note>

Members control who can administer the account. That is separate from [who can sign](/docs/swift/business-accounts/manage-signers). `BusinessAccountMemberRole` has three values:

| Role      | Can do                                                                 |
| --------- | ---------------------------------------------------------------------- |
| `.owner`  | Everything, including transferring ownership. Exactly one per account. |
| `.admin`  | Add and remove members and signers, and link wallets.                  |
| `.viewer` | Read-only access.                                                      |

<Info>
  Adding someone as a member does not let them sign, and adding a signer does not grant admin rights. Grant each explicitly.
</Info>

## Add a member

`addMember` adds a member as `.admin` or `.viewer` (it defaults to `.viewer`). Identify them with a known `userId`, or with an `identifier` plus `identifierType`, in which case the user is created if they do not exist yet.

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

let sdk = DynamicSDK.instance()

let member = try await sdk.businessAccounts.addMember(
    businessAccountId: account.id,
    identifier: "admin@acme.com",
    identifierType: .email,
    role: .admin
)

print(member.userId)
```

<ParamField path="businessAccountId" type="String" required>
  The account to add the member to.
</ParamField>

<ParamField path="userId" type="String?">
  A known Dynamic user ID. Use this instead of `identifier`.
</ParamField>

<ParamField path="identifier" type="String?">
  An email, phone number, or other identifier for the user.
</ParamField>

<ParamField path="identifierType" type="BusinessAccountSignerIdentifierType?">
  How to read `identifier`: `.email`, `.phoneNumber`, `.externalUserId`, `.socialUsername`, `.socialAccountId`, or `.id`.
</ParamField>

<ParamField path="role" type="BusinessAccountMemberRole?">
  `.admin` or `.viewer`. Defaults to `.viewer`.
</ParamField>

## List members

`get` returns the account with its members, including each member's role.

```swift theme={"system"}
let detail = try await sdk.businessAccounts.get(businessAccountId: account.id)

for member in detail.members {
    print("\(member.userId): \(member.role.rawValue)")
}
```

## Change a member's role

`updateMemberRole` moves a member between `.admin` and `.viewer`. To change who the owner is, transfer ownership instead.

```swift theme={"system"}
let updated = try await sdk.businessAccounts.updateMemberRole(
    businessAccountId: account.id,
    userId: member.userId,
    role: .viewer
)
```

## Remove a member

```swift theme={"system"}
let removed = try await sdk.businessAccounts.removeMember(
    businessAccountId: account.id,
    userId: member.userId
)
```

<Tip>
  Removing a member also tears down any [signer](/docs/swift/business-accounts/manage-signers) entries they held on the account's wallets, so they lose signing access too, not just admin rights.
</Tip>

## Transfer ownership

`transferOwnership` promotes an existing member to owner and demotes the current owner to `.admin` in the same operation. Owner only.

```swift theme={"system"}
let detail = try await sdk.businessAccounts.transferOwnership(
    businessAccountId: account.id,
    newOwnerUserId: newOwnerUserId
)
```

<Warning>
  Transferring ownership revokes the caller's session server-side, because their scope changed from owner to admin. The previous owner is signed out and must re-authenticate to pick up the new role. The new owner must already be a member.
</Warning>

## Next steps

<CardGroup cols={2}>
  <Card title="Manage signers" icon="key" href="/docs/swift/business-accounts/manage-signers">
    Grant and revoke signing access per wallet.
  </Card>

  <Card title="Sign transactions" icon="signature" href="/docs/swift/business-accounts/signing">
    Sign with a business-account wallet.
  </Card>
</CardGroup>
