The SDK supports tree-shakeable subpath imports. You can import focused modules directly to minimize your bundle size:
@guildpass/sdk/client: MainGuildPassClientclass.@guildpass/sdk/errors: Error classes and codes (GuildPassError,GuildPassErrorCode).@guildpass/sdk/utils: Utility functions (normaliseAddress,validateAddress,formatIsoDate, etc.).@guildpass/sdk/types: TypeScript definitions.
You can also import everything from the root @guildpass/sdk.
The main constructor.
new GuildPassClient(config: GuildPassClientConfig)getConfig(): Returns the current configuration.
Checks if a wallet can access a resource.
- Returns:
Promise<AccessCheckResult>
Checks access for multiple resources or wallets concurrently.
- Returns:
Promise<AccessCheckBatchResult[]>
Checks if a wallet has a specific role.
- Returns:
Promise<boolean>
Fetches detailed membership status.
- Returns:
Promise<Membership>
Quick check for active membership.
- Returns:
Promise<boolean>
Fetches all roles for a guild.
- Returns:
Promise<GuildRole[]>
Fetches roles assigned to a user.
- Returns:
Promise<GuildRole[]>
Fetches basic guild metadata.
- Returns:
Promise<Guild>
Fetches full guild configuration.
- Returns:
Promise<GuildConfig>
Fetches the owner wallet address for a guild through the configured JSON-RPC provider and contract address.
await client.contracts.getGuildOwner({
guildId: 'guild_1',
chainId: 8453, // optional chain override
contractAddress: '0x0000000000000000000000000000000000000000', // optional contract override
});- Returns:
Promise<string> - Requires: an
rpcUrland a contract address from the resolved chain config or per-callcontractAddress - Contract call:
eth_calltogetGuildOwner(bytes32) - Guild ID encoding: accepts a 32-byte hex value, unsigned integer string, or UTF-8 string up to 32 bytes
- Errors: throws
INVALID_CONFIGfor missing RPC/contract config,INVALID_INPUTfor invalid guild IDs,INVALID_ADDRESSfor invalid contract addresses,HTTP_ERRORfor RPC failures, andINVALID_RESPONSEfor malformed RPC return data
Fetches the raw membership token balance for a wallet through the configured JSON-RPC provider and contract address.
await client.contracts.getMembershipTokenBalance({
walletAddress: '0x1234567890123456789012345678901234567890',
chainId: 8453, // optional chain override
contractAddress: '0x0000000000000000000000000000000000000000', // optional contract override
});- Returns:
Promise<string> - Requires:
rpcUrland eithercontractAddressin client config or a per-call override - Contract call:
eth_calltobalanceOf(address) - Errors: throws
INVALID_CONFIGfor missing RPC/contract config,INVALID_ADDRESSfor invalid wallet or contract addresses,HTTP_ERRORfor RPC failures, andINVALID_RESPONSEfor malformed RPC return data
By default, service methods trust that the API response matches the declared TypeScript return type. Since that's only a compile-time guarantee, a malformed or incompatible response from the API (or a misbehaving mock/proxy in front of it) would otherwise be returned to your code as-is.
Set validateResponses: true in the client config to opt into runtime
checks on responses for the core public types (AccessCheckResult,
Membership, GuildRole, Guild, GuildConfig):
const client = new GuildPassClient({
apiUrl: '...',
validateResponses: true,
});When enabled, a response that doesn't match the expected shape causes
the SDK method to throw a GuildPassError with
code: GuildPassErrorCode.INVALID_RESPONSE, instead of silently
returning malformed data:
try {
await client.access.checkAccess({ ... });
} catch (error) {
if (error instanceof GuildPassError && error.code === GuildPassErrorCode.INVALID_RESPONSE) {
// The API returned a response that doesn't match AccessCheckResult.
}
}This flag defaults to false to preserve existing behaviour for
current consumers. The guards themselves (isAccessCheckResult,
isMembership, isGuildRoleArray, isGuild, isGuildConfig) are
also exported directly from the package if you want to validate
responses yourself without enabling the flag:
import { isGuild } from '@guildpass/sdk';
if (!isGuild(someUnknownValue)) {
// handle the malformed payload
}The guards are hand-written, dependency-free type predicates — no schema validation library is used, so enabling this option has a negligible effect on bundle size.
The SDK maintains an API schema fixture to ensure request and response assumptions are valid. Contract tests (tests/services.test.ts) assert that SDK method parameters map to the correct API endpoint and match expected schema response structures.
When the API contract changes, you must update the fixture (tests/fixtures/api-contract.json) to reflect the new structure:
- Locate the endpoint within
api-contract.json. - Update the
request.pathorrequest.queryarray if parameters change. - Update the
response.successobject to match the new successful response. - Update the
response.errorobject if error formats change. - Run
npm testto verify your SDK methods conform to the new API schema.