With Privy, you can pregenerate self-custodial Ethereum and Solana embedded wallets for existing users, or create a new user with other login methods, like an email address or phone number, without requiring the user to login.
You can even send assets to the wallet before the user logs in to your app for the first time.
Once the user associated with the account logs in, they will be able to access the pregenerated wallet and any assets sent to them.
Pregenerating wallets for new users
To pregenerate embedded wallets for a given user, use the importUser
method from PrivyClient
.
importUser : ({ linkedAccounts : LinkedAccountType [], customMetadata ?: CustomMetadataType , wallets ?: WalletCreateRequestType []}) => Promise < User >
Usage const user = await privy . importUser ({
linkedAccounts: [
{
type: 'email' ,
address: '[email protected] ' ,
},
],
customMetadata: {
username: 'name' ,
isVerified: true ,
age: 23 ,
},
wallets: [
{
chainType: 'ethereum' ,
createSmartWallet: true ,
additionalSigners: [
{
signerId: '<signer-id>' ,
policyIds: [ '<policy-id>' ]
}
]
},
{
chainType: 'solana' ,
additionalSigners: [
{
signerId: '<signer-id>' ,
policyIds: [ '<policy-id>' ]
}
]
}
]
});
See all 34 lines
Params linkedAccounts
LinkedAccountType[]
required
An array of linked accounts to associate with the user.
(Optional) Custom metadata to associate with the user.
wallets
WalletCreateRequestType[]
(Optional) An array of wallets to create for the user.
chainType
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui'
required
The chain type of the wallet to create.
List of policy IDs for policies that should be enforced on the wallet. Currently, only one policy is supported per wallet.
Set to true
to create a smart wallet with the user’s wallet as the signer. Can only be set on wallets where chain_type
is ethereum
.
Returns The user with the newly created wallets.
To pregenerate embedded wallets for a given user, use the importUser
method from PrivyClient
.
importUser : ({ linkedAccounts : LinkedAccountType [], customMetadata ?: CustomMetadataType , wallets ?: WalletCreateRequestType []}) => Promise < User >
Usage const user = await privy . importUser ({
linkedAccounts: [
{
type: 'email' ,
address: '[email protected] ' ,
},
],
customMetadata: {
username: 'name' ,
isVerified: true ,
age: 23 ,
},
wallets: [
{
chainType: 'ethereum' ,
createSmartWallet: true ,
additionalSigners: [
{
signerId: '<signer-id>' ,
policyIds: [ '<policy-id>' ]
}
]
},
{
chainType: 'solana' ,
additionalSigners: [
{
signerId: '<signer-id>' ,
policyIds: [ '<policy-id>' ]
}
]
}
]
});
See all 34 lines
Params linkedAccounts
LinkedAccountType[]
required
An array of linked accounts to associate with the user.
(Optional) Custom metadata to associate with the user.
wallets
WalletCreateRequestType[]
(Optional) An array of wallets to create for the user.
chainType
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui'
required
The chain type of the wallet to create.
List of policy IDs for policies that should be enforced on the wallet. Currently, only one policy is supported per wallet.
Set to true
to create a smart wallet with the user’s wallet as the signer. Can only be set on wallets where chain_type
is ethereum
.
Returns The user with the newly created wallets.
To pregenerate embedded wallets for a given user, make a POST request to https://auth.privy.io/api/v1/users
.
Usage Below is a sample cURL command for generating a new wallet for a user with Privy:
$ curl --request POST https://auth.privy.io/api/v1/users \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "Content-Type: application/json" \
-d '{
"wallets": [
{
"chain_type": "ethereum",
"additional_signers": [
{
"signer_id": "<signer-id>",
"policy_ids": ["<policy-id>"]
}
]
},
{
"chain_type": "solana",
"additional_signers": [
{
"signer_id": "<signer-id>",
"policy_ids": ["<policy-id>"]
}
]
}
],
"linked_accounts": [
{
"address": "[email protected] ",
"type": "email"
}
]
}'
A successful response will include the new user object along with their user ID and embedded wallet address, like below:
{
"id" : "did:privy:clddy332f002tyqpq3b3lv327" ,
"created_at" : 1674788927 ,
"linked_accounts" : [
{
"address" : "[email protected] " ,
"type" : "email"
},
{
"address" : "0x3DAF84b3f09A0E2092302F7560888dBc0952b7B7" ,
"type" : "wallet" ,
"walletClient" : "privy" ,
"chain_type" : "ethereum"
}
]
}
Parameters linked_accounts
LinkedAccountType[]
required
An array of linked accounts to associate with the user.
(Optional) Custom metadata to associate with the user.
wallets
WalletCreateRequestType[]
(Optional) An array of wallets to create for the user.
chain_type
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui'
required
The chain type of the wallet to create.
List of policy IDs for policies that should be enforced on the wallet. Currently, only one policy is supported per wallet.
Set to true
to create a smart wallet with the user’s wallet as the signer. Can only be set on wallets where chain_type
is ethereum
.
Creating wallets for existing users
To create embedded wallets for an existing user, use the createWallets
method from PrivyClient
.
createWallets : ({ userId : string , wallets ?: WalletCreateRequestType []}) => Promise < User >
Usage const user = await privy . createWallets ({
userId: 'did:privy:clddy332f002tyqpq3b3lv327' ,
wallets: [
{
chainType: 'ethereum' ,
createSmartWallet: true ,
},
{
chainType: 'solana' ,
}
]
});
Params The Privy user ID to create wallets for.
wallets
WalletCreateRequestType[]
(Optional) An array of wallets to create for the user.
chainType
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui'
required
The chain type of the wallet to create.
List of policy IDs for policies that should be enforced on the wallet. Currently, only one
policy is supported per wallet.
Set to true
to create a smart wallet with the user’s wallet as the signer. Can only be set
on wallets where chainType
is ethereum
.
Returns The user with the newly created wallets.
To create embedded wallets for an existing user, use the createWallets
method from PrivyClient
.
createWallets : ({ userId : string , wallets ?: WalletCreateRequestType []}) => Promise < User >
Usage const user = await privy . createWallets ({
userId: 'did:privy:clddy332f002tyqpq3b3lv327' ,
wallets: [
{
chainType: 'ethereum' ,
createSmartWallet: true ,
},
{
chainType: 'solana' ,
}
]
});
Params The Privy user ID to create wallets for.
wallets
WalletCreateRequestType[]
(Optional) An array of wallets to create for the user.
chainType
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui'
required
The chain type of the wallet to create.
List of policy IDs for policies that should be enforced on the wallet. Currently, only one
policy is supported per wallet.
Set to true
to create a smart wallet with the user’s wallet as the signer. Can only be set
on wallets where chainType
is ethereum
.
Returns The user with the newly created wallets.
To pregenerate embedded wallets for a given user, make a POST request to https://auth.privy.io/api/v1/apps/<your-app-id>/users/wallet
.
Usage Below is a sample cURL command for generating a new wallet for a user with Privy:
$ curl --request POST https://auth.privy.io/api/v1/apps/ < your-privy-app-i d > /users/wallet \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "Content-Type: application/json" \
-d '{
"user_id": "did:privy:clddy332f002tyqpq3b3lv327",
"wallets": [
{
"chain_type": "ethereum",
"additional_signers": [
{
"signer_id": "<signer-id>",
"override_policy_ids": ["<policy-id>"]
}
],
"create_smart_wallet": true
}
]
}'
A successful response will include the new user object along with their user ID and embedded wallet address, like below:
{
"id" : "did:privy:clddy332f002tyqpq3b3lv327" ,
"created_at" : 1674788927 ,
"linked_accounts" : [
{
"address" : "[email protected] " ,
"type" : "email"
},
{
"address" : "0x3DAF84b3f09A0E2092302F7560888dBc0952b7B7" ,
"type" : "wallet" ,
"walletClient" : "privy" ,
"chain_type" : "ethereum"
}
]
}
Parameters The Privy user ID to create wallets for.
wallets
WalletCreateRequestType[]
(Optional) An array of wallets to create for the user.
chain_type
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui'
required
The chain type of the wallet to create.
List of policy IDs for policies that should be enforced on the wallet. Currently, only one policy is supported per wallet.
Set to true
to create a smart wallet with the user’s wallet as the signer. Can only be set on wallets where chain_type
is ethereum
.