When to Use the API
Use the Portal API when:- Creating wallets from a backend service
- Using predefined policies from the Developer Portal
- Leveraging the paymaster for sponsored wallet creation
- Managing wallets at scale
- Building client-side applications
- Users control their own keypairs
- You need full control over wallet configuration
- Not using the Developer Portal policies
Prerequisites
Before creating wallets via the API, ensure you have:- An API key created in the Developer Portal
- A policy configured (with or without a signer)
- The paymaster public key (provided by Swig or your own paymaster)
Installing the SDK
- API SDK
- Developer SDK
Creating a Swig Wallet
Using the REST API
Make a POST request to the wallet creation endpoint:Using the SDK
- API SDK
- Developer SDK
SDK Comparison
| Feature | @swig-wallet/api | @swig-wallet/developer |
|---|---|---|
| Error handling | Returns { data, error } | Throws SwigError |
| Method name | client.wallet.create() | client.createWallet() |
| Response type | Basic object | Same basic object |
| Best for | Low-level control | Developer convenience |
Request Parameters
Required Parameters
| Parameter | Type | Description |
|---|---|---|
policyId | string | The policy ID from the Developer Portal |
network | 'mainnet' | 'devnet' | Target Solana network |
paymasterPubkey | string | Public key of the paymaster covering fees |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
swigId | string | Custom Swig ID (auto-generated if not provided) |
signerId | string | Override or provide signer ID when policy has no signer |
Response Fields
| Field | Type | Description |
|---|---|---|
swigId | string | The 8-byte identifier for this Swig wallet |
swigAddress | string | The on-chain PDA address of the wallet |
signature | string | The transaction signature (viewable on explorer) |
Examples
Basic Wallet Creation
- API SDK
- Developer SDK
With Custom Swig ID
- API SDK
- Developer SDK
With Signer Override
If your policy doesn’t have a signer attached, or you want to use a different signer:- API SDK
- Developer SDK
Production Wallet
- API SDK
- Developer SDK
Error Handling
- API SDK
- Developer SDK
Common Errors
| Status | Code | Meaning |
|---|---|---|
| 400 | BAD_REQUEST | Invalid request parameters |
| 401 | UNAUTHORIZED | Invalid or missing API key |
| 404 | NOT_FOUND / POLICY_NOT_FOUND | Policy or signer not found |
| 409 | CONFLICT / SWIG_ID_EXISTS | Swig ID already exists |
| 500 | INTERNAL_ERROR | Server error, try again |
Complete Example
- API SDK
- Developer SDK
TypeScript Types
Comparison: API vs Direct SDK
| Feature | Portal API | Direct SDK |
|---|---|---|
| Uses predefined policies | Yes | No |
| Requires API key | Yes | No |
| Paymaster sponsored | Yes | Optional |
| Full configuration control | Limited to policy | Full |
| Best for | Backend services | Client apps |
| Keypair management | Server-side | Client-side |
Next Steps
After creating a wallet, you can:- View the wallet on Solana Explorer
- Sign transactions using the wallet
- Manage authorities to add more signers

