Building Organization Queries

This guide is for you to build queries on your own if you find that the existing developer guides don't have the information you need.

You can query for an Organization directly even though they are a resource tied to a specific User. You may query them directly using their ID through the organization query.

This approach is useful when you have the orgId and do not want to query the viewer first. With your orgId, you can use the following query to get the name of your Organization:

💡 Quick tip: You can tweak the following query around with the GraphQL Explorer to see what other fields are available, these will be automatically suggested to you because of GraphQL's strongly typed schema.

QueryGraphQL
query {
  # Replace the orgId below with your orgId
  organization(orgId: "868202983161") {
    name
  }
}

This will yield the following response:

ResponseJSON
{
  "data": {
    "organization": {
      "name": "My Organization"
    }
  }
}

Organization Relationships

All other relationships are tied to the Organization, so you can query them directly from the Organization object. Check the reference object Organization for a list of all the available fields and relationships.

QueryGraphQL
query {
  # Replace the orgId below with your orgId
  organization(orgId: "868202983161") {
    networks(first: 5) {
      edges {
        node {
          networkId
          network {
            protocolName
            networkName
            nativeAsset {
              networkAssetId
              name
              identifier
              symbol
              decimals
              price {
                priceUsd
                priceChangePercentage24h
                updatedAt
              }
            }
          }
        }
      }
    }
  }
}

This will yield the following response, where you can retrieve the list of blockchain networks and their native assets:

ResponseJSON
{
  "data": {
    "organization": {
      "networks": {
        "edges": [
          {
            "node": {
              "networkId": "a3fbe3f1-079c-4277-83d4-da14337ae795",
              "network": {
                "protocolName": "Ethereum",
                "networkName": "Goerli Testnet",
                "nativeAsset": {
                  "networkAssetId": "cdfef64e-d040-4f1b-bc71-5955d0442305",
                  "name": "GoerliEther",
                  "identifier": "caip19:eip155:5/slip44:60",
                  "symbol": "ETH",
                  "decimals": 18,
                  "price": {
                    "priceUsd": "1617.278152933827",
                    "priceChangePercentage24h": "1.52206544",
                    "updatedAt": "2023-09-28T07:14:05.372Z"
                  }
                }
              }
            }
          },
          {
            "node": {
              "networkId": "3e467c19-1cce-4e6b-837d-df7e7ca0aa5f",
              "network": {
                "protocolName": "Binance Smart Chain",
                "networkName": "Testnet",
                "nativeAsset": {
                  "networkAssetId": "467a3892-f283-4dc1-bed6-79a9b1d15933",
                  "name": "BNB",
                  "identifier": "caip19:eip155:97/slip44:714",
                  "symbol": "BNB",
                  "decimals": 18,
                  "price": {
                    "priceUsd": "212.70801713127193",
                    "priceChangePercentage24h": "-0.11441749",
                    "updatedAt": "2023-09-28T07:14:05.781Z"
                  }
                }
              }
            }
          },
          {
            "node": {
              "networkId": "6c0bd9a3-e780-4336-8886-440f47ba2951",
              "network": {
                "protocolName": "Arbitrum",
                "networkName": "Goerli Testnet",
                "nativeAsset": {
                  "networkAssetId": "e5b1092b-32f4-40dd-b7c3-c71cf2298333",
                  "name": "Ether",
                  "identifier": "caip19:eip155:421613/slip44:60",
                  "symbol": "ETH",
                  "decimals": 18,
                  "price": {
                    "priceUsd": "1617.278152933827",
                    "priceChangePercentage24h": "1.52206544",
                    "updatedAt": "2023-09-28T07:14:05.651Z"
                  }
                }
              }
            }
          },
          {
            "node": {
              "networkId": "3b0533ea-62c2-491f-bd26-80627f84cbe2",
              "network": {
                "protocolName": "Ethereum",
                "networkName": "Sepolia Testnet",
                "nativeAsset": {
                  "networkAssetId": "8846a4dd-ab9d-4fae-952c-1ef5f1b11dac",
                  "name": "Sepolia Ether",
                  "identifier": "caip19:eip155:11155111/slip44:60",
                  "symbol": "ETH",
                  "decimals": 18,
                  "price": {
                    "priceUsd": "1617.278152933827",
                    "priceChangePercentage24h": "1.52206544",
                    "updatedAt": "2023-09-28T07:14:05.372Z"
                  }
                }
              }
            }
          },
          {
            "node": {
              "networkId": "21ab1b28-37e1-4c11-beb1-38491828d9c1",
              "network": {
                "protocolName": "Polygon",
                "networkName": "Mumbai Testnet",
                "nativeAsset": {
                  "networkAssetId": "2757b904-bc51-4511-b68a-e78741443b39",
                  "name": "Matic",
                  "identifier": "caip19:eip155:80001/slip44:966",
                  "symbol": "MATIC",
                  "decimals": 18,
                  "price": {
                    "priceUsd": "0.5099124202020623",
                    "priceChangePercentage24h": "0.06556059",
                    "updatedAt": "2023-09-28T07:14:05.651Z"
                  }
                }
              }
            }
          }
        ]
      }
    }
  }
}

Viewer Wallets

Although the Wallet is a resource tied to a specific Organization, an actor's ability to access them is determined by the User role within the Organization. Therefore, to query available wallets for the current viewer with your orgId, you may write the following query:

QueryGraphQL
query {
  # Replace the orgId below with your orgId
  organization(orgId: "868202983161") {
    viewer {
      wallets(first: 10) {
        edges {
          node {
            walletId
            name
          }
        }
      }
    }
  }
}

This will yield the following response:

ResponseJSON
{
  "data": {
    "organization": {
      "viewer": {
        "wallets": {
          "edges": [
            {
              "node": {
                "walletId": "22cf4347-405a-47df-8267-26bfecac7b11",
                "name": "Test Wallet"
              }
            }
          ]
        }
      }
    }
  }
}

Querying Wallet with ID

Similar to the Organization object, you may query Wallet directly by referencing the walletId and Organization orgId.

QueryGraphQL
query {
  # Replace the orgId below with your orgId
  organization(orgId: "868202983161") {
    # Replace the orgId below with your walletId
    wallet(walletId: "22cf4347-405a-47df-8267-26bfecac7b11") {
      # Wallet details
      walletId
      name
      organizationNetwork {
        networkId
        organizationNetworkId
        network {
          protocolName
          networkName
        }
      }
      # Wallet type, e.g. SimpleMultiSig, Safe, etc.
      type
      # Get list of users with minimally Viewer access to wallet
      accesses {
        edges {
          node {
            walletAccessId
            memberId
            organizationMember {
              user {
                firstName
                lastName
                email
              }
            }
            role
          }
        }
      }
      policy {
        # Approval threshold
        approvalThreshold
        # Whitelisted addresses
        whitelists {
          edges {
            node {
              label
              address
            }
          }
        }
        finalApprovers {
          edges {
            node {
              finalApproverId
            }
          }
        }
      }

      # Get gas tank details
      gasTank {
        gasTankId
        address
        isPrimary
        gasTankKey {
          keyId
          key {
            publicKey
          }
        }
      }
      # Get the keys that are part of this wallet
      walletKeys {
        key {
          keyId
          publicKey
          keyType # See Levain's Wallet Security Model
          type
        }
      }

      # Get tx hash of wallet creation, to check on respective block explorer
      txHash
      # Get wallet deployment status
      status
    }
  }
}

This will yield the following response:

ResponseJSON
{
  "data": {
    "organization": {
      "wallet": {
        "walletId": "22cf4347-405a-47df-8267-26bfecac7b11",
        "name": "Test",
        "organizationNetwork": {
          "networkId": "21ab1b28-37e1-4c11-beb1-38491828d9c1",
          "organizationNetworkId": "b60e5c14-59ce-4cea-ad34-309de16c12c6",
          "network": {
            "protocolName": "Polygon",
            "networkName": "Mumbai Testnet"
          }
        },
        "type": "EvmContractSimpleMultiSig",
        "accesses": {
          "edges": [
            {
              "node": {
                "walletAccessId": "653af160-cf4f-4883-847e-7c2fca88fdbc",
                "memberId": "88fc43d8-6698-4c04-b4e2-d29996a39a3e",
                "organizationMember": {
                  "user": {
                    "firstName": "John",
                    "lastName": "Doe",
                    "email": "[email protected]"
                  }
                },
                "role": "APPROVER"
              }
            }
          ]
        },
        "policy": {
          "approvalThreshold": 1,
          "whitelists": {
            "edges": []
          },
          "finalApprovers": {
            "edges": [
              {
                "node": {
                  "finalApproverId": "0446a419-9457-4e7c-8370-5772a783f99d"
                }
              }
            ]
          }
        },
        "gasTank": {
          "gasTankId": "0d3e919a-e15b-449b-9e35-dcd1038b16c0",
          "address": "0x21EdBcb2134F157b75C31C116D8dd03C05c4418A",
          "isPrimary": false,
          "gasTankKey": {
            "keyId": "9a694bba-0785-43d3-8a6a-aaf33451f2a5",
            "key": {
              "publicKey": "02b33989803c545073f3e1db26fc8034b57a07f85cd8efe6dd5e0267b963762ea4"
            }
          }
        },
        "walletKeys": [
          {
            "key": {
              "keyId": "eb6862f2-43a2-4057-b6c9-32aff9c15279",
              "publicKey": "0x02cfe2f4aa624d196bf9d5650c4dbe16cea663238c3b96b9b145fe6631d80a003b",
              "keyType": "MAIN",
              "type": "SCALAR_NEUTERED"
            }
          },
          {
            "key": {
              "keyId": "85bb85fb-8e25-4626-a7e1-576cf81bf0f6",
              "publicKey": "0x02a3fe0d33a680bbdc51d89d35829560ec24ba8c49a98536fa70eff4108f34a5d8",
              "keyType": "BACKUP",
              "type": "SCALAR_NEUTERED"
            }
          },
          {
            "key": {
              "keyId": "9a694bba-0785-43d3-8a6a-aaf33451f2a5",
              "publicKey": "02b33989803c545073f3e1db26fc8034b57a07f85cd8efe6dd5e0267b963762ea4",
              "keyType": "LEVAIN",
              "type": "BIP32_HARDENED"
            }
          }
        ],
        "txHash": "0x2e2ff0748250e1e2fd2cd50a461b3ad680640980464fe5a35ba2a88e295331f4",
        "status": "ACTIVE"
      }
    }
  }
}