Before you can add Wallet Service to your Android app, you need to create a Particle project to connect to your Android app. Visit Particle Dashboard to learn more about Particle projects and apps.
Declare them in your module (app-level) Gradle file (usually app/build.gradle).
repositories {google()mavenCentral()maven { setUrl("https://jitpack.io") }//...}dependencies {//required modules {module("org.bouncycastle:bcprov-jdk15to18") {replacedBy("org.bouncycastle:bcprov-jdk15on") } }// pick one of two, implementation 'network.particle:connect-auth-adapter:{latest-version}'//implementation 'network.particle:connect-auth-core-adapter:{latest-version}'// Particle Wallet Core Apiimplementation("network.particle:api-service:${latest_version}")// Particle Wallet GUI, you can remove it if custom GUI.implementation("network.particle:wallet-service:${latest_version}")//find the latest version of the sdk://https://search.maven.org/search?q=g:network.particle//...}
repositories { google() mavenCentral() maven { url "https://jitpack.io" }//...}dependencies {// Particle Auth Service implementation 'network.particle:auth-service${latest_version}'// Particle Wallet Api implementation 'network.particle:wallet-service-api${latest_version}'// Particle Wallet GUI, you can remove it if custom GUI. implementation 'network.particle:wallet-service${latest_version}'//...}
The Wallet Service can only be used after a successful log-in with Connect Service.
Wallet Service depends on Connect Service, you must import Connect Service.
If you want to receive release updates, subscribe to our GitHub repository.
Wallet Core Reference
Initialize the SDK
classApp : Application() {overridefunonCreate() {super.onCreate()//init Particle SDK for solana chain ParticleNetwork.init(this, Env.DEV, ChainInfo.Ethereum)//init wallet service/** * supportChains is optional, if not provided, all chains will be supported * if provided, only the chains in the list will be supported,Only the main chain is required, * if you want to support devnet, you can call showTestNetworks() to show the devnet networks */val supportChains =mutableListOf( ChainInfo.Ethereum, ChainInfo.BNBChain, ChainInfo.Solana ) ParticleWallet.init(this,supportChains).apply {showTestNetworks() // show test networks,default is hidehideManageWallet() // hide manage wallet item in setting page,default is show } }}
Solana Service
Get the real-time exchange rate of the Solana token
// call enhanced method: enhancedGetTokensAndNFTs//fetch from server、save to db and return ParticleNetwork.solana.getTokensAndNFTs(address)//get data from db onlyParticleNetwork.solana.getTokensAndNFTsFromDB(address)
Get parsed transaction history by giving an address
// call enhanced method: enhancedGetTransactionsByAddressParticleNetwork.solana.getTransactionsByAddress(address, optBody)//get trans from dbParticleNetwork.solana.getTransactionsByAddressFromDB(address, optBody)
// such as getBalanceParticleNetwork.solana.rpc("getBalance", listOf("8FE27ioQh3T7o22QsYVT5Re8NnHFqmFNbdqwiF3ywuZQ"))
Add Custom Tokens
// publicKey is your user public publicKeyval publicKey = ParticleNetwork.getPublicKey()// tokenAddresses is token contract addressval tokenList =listOf("Fm9rHUTF5v3hwMLbStjZXqNBBoZyGriQaFM6sTFz3K8A")// if tokens are existed in blockchain, will return them.// if no tokens existed in blockchain, will return empty list.ParticleNetwork.solana.addCustomTokens(publicKey, tokenList)
EVM Service
Get the real-time exchange rate of the EVM token
val parmas1 =arrayListOf("native") val parmas2 =arrayListOf("usd") val rateResultList = ParticleNetwork.evm.getPrice(parmas1, parmas2)
Get token list and NFT list by giving an address
// call enhanced method: particle_getTokensAndNFTs//fetch from server、save to db return result ParticleNetwork.evm.getTokensAndNFTs(address)//get data from db onlyParticleNetwork.evm.getTokensAndNFTsFromDB(address)
Get parsed transaction history by giving an address
// call enhanced method: particle_getTransactionsByAddressParticleNetwork.evm.getTransactionsByAddress(address)//get data from db onlyParticleNetwork.evm.getTransactionsByAddressFromDB(address)
Get suggested GasFees
ParticleNetwork.evm.suggestedGasFees()
Get Token info list
// get any EVM chain all token infoParticleNetwork.evm.getTokenList()
// such as eth_estimateGasParticleNetwork.evm.rpc("eth_estimateGas",listOf(mapOf("from" to "0xXXX...", "to" to "0xXXX...")))
Read Contract
// example for evm read contractprivatesuspendfunreadContract() { ParticleNetwork.evm.readContract("0xd000f000aa1f8accbd5815056ea32a54777b2fc4","balanceOf",listOf("0xBbc1CA8776EfDeC12C75e218C64e96ce52aC6671") )}
Write Contract
// example for evm write contract// mint 1 NFT in kovan testnet, the from is sender address or user address in general.// result is a transaciton string which presented in hex format.privatesuspendfunwriteContract() {val params = ContractParams.customAbiEncodeFunctionCall( contractAddress ="0xd000f000aa1f8accbd5815056ea32a54777b2fc4", methodName ="mint", params =listOf("1") ) ParticleNetwork.evm.writeContract("0xd000f000aa1f8accbd5815056ea32a54777b2fc4", params )}
Add Custom Tokens
// address is your user public addressval address = ParticleNetwork.getAddress()// tokenAddresses is token contract addressval tokenList =listOf("Fm9rHUTF5v3hwMLbStjZXqNBBoZyGriQaFM6sTFz3K8A")// if tokens are existed in blockchain, will return them.// if no tokens existed in blockchain, will return empty list.ParticleNetwork.evm.addCustomTokens(address, tokenList)
Serialize the data of any contract
ParticleNetwork.evm.abiEncodeFunctionCall(params: List<Any>)ParticleNetwork.evm.abiEncodeFunctionCall(contractAddress: String,method: String,params: List<Any>,json: String="")//The above two methods work the same.// 1. The first parameter is contract address// 2. The second parameter is the name of the method to be called.// Currently, we support:'erc20_transfer'、'erc20_approve'、'erc20_transferFrom'、'erc721_safeTransferFrom'、'erc1155_safeTransferrom'
// or arbitrary method call: 'custom_{methodName}'// for example if you need to call mint method, then pass custom_mint as parameter// 3. The third parameter is the parameter value array of the method to be called, which should correspond to the above method.
// 4. The fourth parameter is optional,an ABI JOSN string// For erc20/721/1155 methods we support, this parameter is not needed// And if your contract is verified at the chain's scan website, this parameter is not needed
Serialize the data of stardard contracts
// call 'transfer(to, amount)' function in erc20suspendfunerc20Transfer(){val contractAddress =""val to=""val amount:BigInteger= BigInteger.valueOf(1111) ParticleNetwork.evm.erc20Transfer(contractAddress,to,amount)}// call 'approve(spender, amount)' function in erc20 suspendfunerc20Approve() {val contractAddress =""val spender =""val amount = BigInteger.valueOf(1111)val result: ResponseBody= ParticleNetwork.evm.erc20Approve(contractAddress, spender, amount)}// call 'transferFrom(from, to, amount)' function in erc20suspendfunerc20TransferFrom() {val contractAddress =""val from =""val to =""val amount = BigInteger.valueOf(1111)val result: ResponseBody= ParticleNetwork.evm.erc20TransferFrom(contractAddress, from, to, amount)}// call 'safeTransferFrom(from, to, tokenId)' function in erc721suspendfunerc721SafeTransferFrom() {val contractAddress =""val from =""val to =""val tokenId =""val result: ResponseBody= ParticleNetwork.evm.erc721SafeTransferFrom(contractAddress, from, to, tokenId)}// call 'safeTransferFrom(from, to, id, amount, data)' function in erc1155suspendfunerc1155SafeTransferFrom() {val contractAddress =""val from =""val to =""val id =""val amount = BigInteger.valueOf(1111)valdata: String; ParticleNetwork.evm.erc1155SafeTransferFrom(contractAddress, from, to, id, amount, data)}
Create Transaction
/** * from: sender address. * to: receiver address or contract address. * value: (optional) hex of the value sent with this transaction. * contractParams: (optional) call contract function params. * type: default value "0x2"(EIP1559), "0x1"(EIP2930), "0x0"(Legacy) * nonce: default value "0x0", particle auth manage nonce without cancel or speed transaction. * gasFeeLevel: default value TransGasFeeMode.medium, transaction gas fee level. * action: detault TxAction.normal. if you cancel/speed tracsaction, set the vaule. * abiEncodeData: the abi_encodeFunctionCall result, default value is null. */val tx = ParticleNetwork.evm.createTransaction(from, to, value, contractParams, type, nonce, gasFeeLevel, action,abiEncodeData)//send transaction with particle authParticleNetwork.signAndSendTransaction(activity, tx.serialize(), callback)
you can call contract function by set contractParams:
ContractParams.erc20Transfer()
ContractParams.erc20Approve()
ContractParams.erc20TransferFrom()
ContractParams.erc721SafeTransferFrom()
ContractParams.erc1155SafeTransferFrom()
ContractParams.customAbiEncodeFunctionCall()
Read Contract
// create tx dataval tx =TxData(null, "0x0", null, from, to ,null, data, ParticleNetwork.chainId.toHexString())//Integer block number, or the string 'latest', 'earliest' or 'pending'val quantity ="latest"//call eth_call rpcval output = ParticleNetwork.evm.rpc("eth_call", listOf(tx, quantity))
Wallet UI Reference
Set pay feature, default support pay feature.
// You can disable pay feature in UI, default is true.ParticleNetwork.enablePay(false)
Control show or hide test network, manage wallet page, support chain.
Because ParticleWalletGUI dependent on Particle Connect, Particle Connect initialize chain will add to support chain automatically.
// show or hide test network, default is false.ParticleWallet.showTestNetworks()// show or hide manage wallet page.ParticleWallet.hideManageWallet()// support chain, Particle Connect initialize chain will add as a support chain automatically.// default support all chains in Particle Network baseParticleWallet.init(context,supportChains)//You can initialize the above configuration with a single statementParticleWallet.init( context, supportChains, ).apply {setShowTestNetworkSetting(true) //default is falsesetShowManageWalletSetting(true) // default is truehideMainBackIcon() // hide the back icon in the main pagesetShowAppearanceSetting(true) //default is truesetShowLanguageSetting(true) //default is truesetSupportDappBrowser(true) //default is truesetWalletIcon("https://xxx.xxx/xxx.png") //set the wallet icon }//set Wallet Name,only support ParticleConnectAdapter after connect successval yourWalletName ="X Wallet"val wallet = WalletInfo.createWallet( ParticleNetwork.getAddress(), ParticleNetwork.chainInfo.name, ParticleNetwork.chainInfo.id,1, yourWalletName, MobileWCWalletName.Particle.name)ParticleWallet.setWallet(wallet)// Set your custom localizable string// Overlay strings.xml YourProject/app/src/main/res/ values/strings.xml values-ja-rJP/strings.xml values-ko-rKR/strings.xml values-zh-rCN/strings.xml values-zh-rHK/strings.xml values-zh-rTW/strings.xmlReassign a value<string name="pn_network_fee">new NetworkFee</string><string name="pn_particle_auth_wallet">New Wallet</string>
// // open buy crypto with parameters// every parameter is optionalParticleNetwork.openBuy( walletAddress: String? =null,//nullable,default is current wallet address amount: Int? =null, //1000 fiatCoin: String="usd", cryptoCoin: String="eth", fixFiatCoin: Boolean=false, fixFiatAmt: Boolean=false, fixCryptoCoin: Boolean=false, theme: String="light", // light or dark language: String="en-us", //en-us、ko-kr、zh-cn、zh-tw、ja-jp chainName: String? = null // ChainInfo.Ethereum.name、ChainInfo.Polygon.name ... , nullable,default ParticleNetwork.chainInfo.name
)
Open Swap
// open default swap pagePNRouter.navigatorSwap()// open swap page with from token, to token, and uiAmount, all parameters is optional.val swapConfig =SwapConfig( fromTokenAddress="", toTokenAddress="", fromTokenUIAmount="0.1" )PNRouter.navigatorSwap(swapConfig)