Interacting with Particle Auth within applications made using React Native.
projectId
, clientKey
, and appId
, all of which can be retrieved from the Particle dashboard.
@particle-network/rn-auth-core
, either through npm or Yarn, depending on your preference.
projectId
, clientKey
, and appId
) within your build.grade
file (generally found at ${project name}/android/app/build.gradle
). These directly link your application’s instance of Particle Auth with the dashboard.
Specifically, within build.gradle
, you’ll need to set four different values:
dataBinding
, this should be enabled with enabled = true
.manifestPlaceholders["PN_PROJECT_ID"]
, the projectId
previously retrieved from the Particle dashboard.manifestPlaceholders["PN_PROJECT_CLIENT_KEY"]
, the clientKey
previously retrieved from the Particle dashboard.manifestPlaceholders["PN_APP_ID"]
, the appId
previously retrieved from the Particle dashboard.ios/{project name}.xcworkspace
.
At the root of your Xcode project, create a new file, ParticleNetwork-Info.plist
. Ensure this is marked under “Target Membership.”
From here, with a fresh ParticleNetwork-Info.plist
file, go ahead and fill it in with the following:
PROJECT_UUID
(projectId
), PROJECT_CLIENT_KEY
(clientKey
), and PROJECT_APP_UUID
(appId
) with the corresponding values retrieved from the Particle dashboard.
Add Privacy - Face ID Usage Description to your info.plist file, head over to your Info.plist
file and include the following snippet:
Specific note for using Expo.
If you’re working with Expo, your Podfile needs additional editing to ensure compatibility with Particle Auth Core, as below:
You can reference this Podfile.
@particle-network/rn-auth-core
, in this case as particleAuthCore
.
@particle-network/rn-base
imported, you’ll need to call the init
function on your representation of @particle-network/rn-base
, which in this case is particleBase
. init
takes the following parameters:
chainInfo
, this refers to an object containing relevant information about the primary chain to be used. ChainInfo
objects can be imported from @particle-network/chains
.env
, imported from @particle-network/rn-auth
, and can be either:
Env.Production
Env.Staging
Env.Dev
particleAuthCore.init
.
particleAuthCore.connect
. Upon calling this method, depending on specific parameters, a popup will be displayed, prompting a user to sign in with a social account, thus leading to the generation and assignment of a wallet. particleAuthCore.connect
takes the following parameters:
Field | Type | Description |
---|---|---|
type | LoginType | The specific social login to be used. This can be either .email , .phone , .google , .apple , .jwt , .facebook , .twitter , .discord , .github , .twitch , .microsoft or linkedin . |
account | string? | (Optional) When type is set to either .email , .phone , or .jwt , you can use the account parameter to pass in an expected email, phone number, or JWT. This is optional for the former two, but required for .jwt . If passing a phone number, it must be in E.164 format. |
supportAuthType | SupportAuthType[] | The methods of authentication visible on the authentication popup UI. By default, this will be exclusive to the chosen social login method, although by passing in additional types, you can expand the UI to include the ability to login with those as an alternative to type. |
prompt | SocialLoginPrompt? | (Optional) Changes what the OAuth provider prompts a user to do; either .none , .consent , or .select_account . Only Google, Discord and Microsoft support it. |
loginPageConfig | LoginPageConfig? | (Optional) to customize the UI page, contains project name, icon and description. |
particleAuthCore.disconnect
method.
particleAuthCore.isConnected
. This method returns a Boolean indicating whether a user is logged in.
evm.getAddress
or solana.getAddress
can be called.
For first-time users, only the address of the current chain will be generated. For example, if the current chain is an EVM chain, the user will only get the EVM address upon first login. If the user also needs a Solana address, they will need to call await particleAuthCore.switchChain(Solana) to obtain it. After switching successfully, the current chain will be changed to Solana, and the user can use solana.getAddress
to get the address.
particleAuthCore.getUserInfo
. This same response will be automatically saved to a successful call of particleAuthCore.connect
.
evm.personalSign
or evm.personalSignUnique
method. If you need the same message to return a unique signature each time, use the evm.personalSignUnique
method. Otherwise, the evm.personalSign
method is generally recommended. On Solana, you can call solana.signMessage
, you can pass in a UTF-8/readable string.
Field | Type | Description |
---|---|---|
message | string | On Evm requires a hexadeciaml string or a UTF-8/readable string, on Solana, requires a UTF-8/readable string |
Field | Type | Description |
---|---|---|
transaction | string | Requires a base58 string |
solana.signAllTransactions
to propose a collection of Solana transactions for signature, rather than just a single transaction.
Field | Type | Description |
---|---|---|
transactions | string[] | Each element requires a base58 string |
evm.sendTransaction
and solana.signAndSendTransaction
will be the primary method used in virtually every scenario. This will propose a signature (on both EVM and Solana), and then immediately push it to the network once confirmed.
Field | Type | Description |
---|---|---|
transaction | string | On Evm requires a hexadeciaml string, on Solana, requires a base58 string |
Evm.signTypedData
or evm.signTypedDataUnique
method. If you need the same message to return a unique signature each time, use the evm.signTypedDataUnique
method. Otherwise, the evm.signTypedData
method is generally recommended.
Field | Type | Description |
---|---|---|
message | string | Requires a hexadeciaml string or a json string |
init
), you can call either particleBase.setChainInfo
(synchronous) or particleAuthCore.switchChain
(asynchronous), ChainInfo
objects can be imported from @particle-network/chains
.
ParticleBase.getChainInfo
. This returns a ChainInfo object containing:
name
, the name of the chain in question (ex: Ethereum).id
, the ID of the chain in question (ex: 11155111).network
, the specific network corresponding to the chain ID (ex: Sepolia)particleBase.setSecurityAccountConfig
and passing in a SecurityAccountConfig
object with two parameters:
Field | Type | Description |
---|---|---|
promptSettingWhenSign | int | The payment (signature) password config prompts (default is 1). |
promptMasterPasswordSettingWhenLogin | int | The master password prompts (default is 0). |
0
means a prompt is never shown requesting this setting.1
means a prompt is shown only upon the first startup.2
means a prompt is shown every time.3
means will force a user to set a password.particleBase.openAccountAndSecurity
.
isConnected
function covered prior, there are various scenarios in which knowing whether or not a user has specific security settings enabled may be useful.
This can be controlled with the built-in particleAuthCore.hasMasterPassword
, particleAuthCore.hasPaymentPassword
, and particleAuthCore.changeMasterPassword
methods.
particleBase.setAppearance
. By default, it will follow current system setting.
Field | Type | Description |
---|---|---|
appearance | Appearance | The specific appearance to be used. This can be either .system , .dark , .light . |
particleBase.setLanguage
, with retrieval of the current active language facilitated by particleBase.getLanguage
. By default, this is set to English.
Field | Type | Description |
---|---|---|
language | Language | The specific language to be used. This can be either .EN , .JA , .ZH_HANS , .ZH_HANT , .KO . |
particleBase.setSecurityAccountConfig
to update its value.Field | Type | Description |
---|---|---|
isoCodeList | string[] | ISO 3166-1 alpha-2 code list, such as the US, the UK, etc. |
EvmService
utilization examples@particle-network/rn-base
is EvmService
, an object for facilitating additional on-chain interaction, leveraging standard and enhanced RPC endpoints. EvmService
can either be accessed through a complete (*
) import (such as is shown above) by using particleBase.EvmService.{method}
or individually importing it from @particle-network/rn-base
.
EvmService.writeContract
allows you to execute a write contract call defined by a specific method and set of parameters. This requires a corresponding ABI, contract address, and requester public address.
Field | Type | Description |
---|---|---|
from | string | The user’s public address. |
value | BigNumber | The value sent with this transaction |
contractAddress | string | The contract address. |
methodName | string | The method name that defined in the contract, such as mint , balanceOf . |
parameters | string[] | The parameters of this method. |
abiJsonString | string | The abi json string of this method. |
gasFeeLevel | GasFeeLevel | (Optional) The gas fee level, high , medium or low , default is high . |
EvmService.readContract
allows you to execute a read-only contract call defined by a specific method and set of parameters. This requires a corresponding ABI, contract address, and requester public address.
Field | Type | Description |
---|---|---|
address | string | The user’s public address. |
value | BigNumber | The value sent with this transaction |
contractAddress | string | The contract address. |
methodName | string | The method name that defined in the contract, such as mint , balanceOf . |
parameters | string[] | The parameters of this method. |
abiJsonString | string | The abi json string of this method. |
EvmService.createTransaction
facilitates the construction of a transaction object derived from the standard from
, to
(receiver
in this example), amount
(value
), and data
fields. This transaction, once constructed with EvmService.createTransaction
, can be passed for in-UI proposal with ParticleAuthCore.sendTransaction
.
Field | Type | Description |
---|---|---|
from | string | The user’s public address. |
data | string | The transaction’s data. |
value | BigNumber | The native amount. |
to | string | If you send a erc20, erc721, erc1155 or interact with a contract, this is the contract address, if you send native, this is receiver address. |
gasFeeLevel | GasFeeLevel | (Optional) the gas fee level, high , medium or low , default is high . |
eth_estimateGas
). This is done through EvmService.estimateGas
.
EvmService.suggestedGasFees
.
EvmService
also extends to Data API methods such as getTokensAndNFTs
, which returns a highly detailed JSON list of ERC20 tokens and ERC721 NFTs belonging to a specified address. This is accessible through EvmService.getTokensAndNFTs
, passing in the public address to retrieve the tokens and NFTs of, also you can retrieve tokens from getTokens
or NFTs from getNFTs
Field | Type | Description |
---|---|---|
address | string | The user’s public address. |
tokenAddresses | string[] | The specific tokens’ addresses |
EvmService.getTransactionsByAddress
enables the retrieval of a detailed JSON response containing a complete list of transactions involving a specified address.
EvmService.getPrice
.
Field | Type | Description |
---|---|---|
tokenAddresses | string[] | The tokens’s addresses, for native token, you can pass "native" |
currencies | string[] | The currency in which the price is denominated, such as "usd" |
EvmService.rpc
, as shown below.
Field | Type | Description |
---|---|---|
method | string | The evm basic rpc method |
params | any | The parameters required by evm basic rpc method |
SolanaService
utilization examplesparticleAuthCore
for authentication and interaction with Particle’s Wallet-as-a-Service, the React Native SDK also includes a class, SolanaService
, for general interaction with Solana chains.
SolanaService
also extends to Data API methods such as getTokensAndNFTs
, which returns a highly detailed JSON list of SPL tokens and NFTs belonging to a specified address. This is accessible through SolanaService.getTokensAndNFTs
, passing in the public address to retrieve the tokens and NFTs of.
Field | Type | Description |
---|---|---|
address | String | The user’s public address. |
parseMetadataUri | bool | If you’d like to parse the NFT’s metadata. |
SolanaService.serializeSolTransaction
facilitates the construction of a SOL transaction object,
SolanaService.serializeSplTokenTransaction
facilitates the construction of a Spl-token transaction object,
SolanaService.serializeWSolTokenTransaction
facilitates the construction of a unwrap WSOL transaction object.
These transactions, once constructed, can be passed for in-UI proposal with Solana.signAndSendTransaction
.
SolanaService.getPrice
.
Field | Type | Description |
---|---|---|
tokenAddresses | string[] | The tokens’s addresses, for native token, you can pass "native" |
currencies | string[] | The currency in which the price is denominated, such as "usd" |
SolanaService.getTransactionsByAddress
.
SolanaService.getTokenByTokenAddresses
Field | Type | Description |
---|---|---|
address | string | The user’s public address. |
tokenAddresses | string[] | The tokens’ addresses |
EvmService
, any basic Solana RPC method can be called through SolanaService.rpc
.
Field | Type | Description |
---|---|---|
method | string | The solana basic rpc method |
params | any | The parameters required by solana basic rpc method |