To use features of ethereum like sending an ERC20 token, you need to use a call method through the EthereumService class that inherits the CoinService interface. The EthereumService class is available to get from the CoinServiceFactory.getCoinService().
CoinServiceFactory includes a static method that is the getCoinService to get the specific inherited CoinService.
CoinNetworkInfo coinNetworkInfo = new CoinNetworkInfo( CoinType.ETH, EthereumNetworkType.MAINNET, RPC_ENDPOINT //ex. https://mainnet.infura.io/v3/xxxxx ); //coinNetworkInfo for EVM supported custom network (ex. Binance Mainnet). CoinNetworkInfo coinNetworkInfo = new CoinNetworkInfo( CoinType.ETH, EthereumNetworkType.BSC_MAINNET, RPC_ENDPOINT //ex. https://bsc-dataseed.binance.org/ ); //coinNetworkInfo for EVM supported custom network (ex. Matic Mainnet). CoinNetworkInfo coinNetworkInfo = new CoinNetworkInfo( CoinType.ETH, EthereumNetworkType.MATIC_MAINNET, RPC_ENDPOINT //ex. https://rpc-mainnet.maticvigil.com/ ); //coinNetworkInfo for EVM supported custom network (ex. Fantom Mainnet). CoinNetworkInfo coinNetworkInfo = new CoinNetworkInfo( CoinType.ETH, EthereumNetworkType.FANTOM_OPERA_MAINNET, RPC_ENDPOINT //ex. https://rpc.fantom.network/ ); EthereumService etherService = (EthereumService) CoinServiceFactory .getCoinService( getApplicationContext(), coinNetworkInfo );
If you want to use a new EthereumService, a CoinNetworkInfo that assigns CoinType.ETH is required. After creation, reassigning of CoinNetworkInfo is not allowed. If you want to change the NetworkType or 'JSON-RPC URL', you should create a new instance through the CoinServiceFactory.getCoinService().
The APIs below will be treated at Simple Payment UI separately.
createEthereumPaymentSheetActivityIntent – Creates an Intent that shows up in the Ethereum Payment Sheet.
createTokenPaymentSheetActivityIntent – Creates an Intent that shows up in the ERC20 token Payment Sheet.
createNftPaymentSheetActivityIntent – Creates an Intent that shows up in the unsafe ERC721 token Payment Sheet.
createSafeNftPaymentSheetActivityIntent – Creates an Intent that shows up in the safe ERC721 token Payment Sheet.
EthereumCoinService class inherits the CoinService. Base APIs are implemented through the EthereumCoinService.
The list below are the APIs in CoinService.
etherService.getBalance(account).setCallback( new ListenableFutureTask.Callback<BigInteger>() { @Override public void onSuccess(BigInteger result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } });
boolean result = etherService.isValidAddress(ethAddress);
getFeeInfo() API has been deprecated in 1.2.00.
Use getFeeInfo(ethereumTransactionType) instead.
EthereumTransactionType ethereumTransactionType = EthereumTransactionType.EIP1559; etherService.getFeeInfo(ethereumTransactionType).setCallback( new ListenableFutureTask.Callback<FeeInfo>() { @Override public void onSuccess(FeeInfo feeInfo) { //success } @Override public void onFailure(@NonNull ExecutionException e) { //failure } @Override public void onCancelled(@NonNull InterruptedException e) { //cancelled } });
RawTransaction rawTx = RawTransaction.createEtherTransaction( chainId, nonce, gasLimit, toAddress, value, maxPriorityFeePerGas, maxFeePerGas ); byte[] encodedTransaction = TransactionEncoder.encode(rawTx); try { etherService.sendRawTransaction( hardwareWalletManager.getConnectedHardwareWallet(), account, encodedTransaction ) .setCallback(new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
EthereumService etherService = (EthereumService) CoinServiceFactory .getCoinService( context, coinNetworkInfo ); etherService.getTransactionDetail(txId) .setCallback( new ListenableFutureTask.Callback<EthereumTransaction>() { @Override public void onSuccess(EthereumTransaction result) { //handle success } @Override public void onFailure(ExecutionException exception) { //handle failure } @Override public void onCancelled(InterruptedException exception) { //handle cancel } });
try { etherService .sendTransaction( connectedWallet, account, EthereumUtils.convertGweiToWei(new BigDecimal(maxPriorityFeePerGas)), EthereumUtils.convertGweiToWei(new BigDecimal(maxFeePerGas)), new BigInteger(gasLimit), toAddress, EthereumUtils.convertEthToWei(new BigDecimal(ethAmount)), null // nonce ).setCallback( new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult result) { //success } @Override public void onFailure(ExecutionException exception) { //fail } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
try { etherService.sendTokenTransaction( connectedWallet, account, toAddress, toContractAddress, EthereumUtils.convertGweiToWei(new BigDecimal(maxPriorityFeePerGas)), EthereumUtils.convertGweiToWei(new BigDecimal(maxFeePerGas)), new BigInteger(gasLimit), new BigInteger(tokenAmount), nonce ).setCallback( new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
try { etherService .sendSmartContractTransaction( hardwareWallet, account, toContractAddress, EthereumUtils.convertGweiToWei(new BigDecimal(maxPriorityFeePerGas)), EthereumUtils.convertGweiToWei(new BigDecimal(maxFeePerGas)), new BigInteger(gasLimit), encodedFunction, value, null // nonce ) .setCallback( new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
try { etherService .sendSafeNftTransaction( hardwareWallet, account, toAddress, toContractAddress, EthereumUtils.convertGweiToWei(new BigDecimal(maxPriorityFeePerGas)), EthereumUtils.convertGweiToWei(new BigDecimal(maxFeePerGas)), new BigInteger(gasLimit), BigInteger.valueOf(NftId), data, null // nonce ) .setCallback( new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
try { etherService .sendNftTransaction( hardwareWallet, account, toAddress, toContractAddress, EthereumUtils.convertGweiToWei(new BigDecimal(maxPriorityFeePerGas)), EthereumUtils.convertGweiToWei(new BigDecimal(maxFeePerGas)), new BigInteger(gasLimit), BigInteger.valueOf(nftId), null // nonce ) .setCallback( new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
try { etherService.signPersonalMessage( hardwareWallet, account, "message".getBytes() ).setCallback(new ListenableFutureTask.Callback<byte[]>() { @Override public void onSuccess(byte[] result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } }); } catch (AvailabilityException e) { //handle exception }
etherService.getTokenInfo(tokenAddress).setCallback( new ListenableFutureTask.Callback<EthereumTokenInfo>() { @Override public void onSuccess(EthereumTokenInfo result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } });
etherService.estimateGasLimit( account, toAddress, value, data ).setCallback(new ListenableFutureTask.Callback<BigInteger>() { @Override public void onSuccess(final BigInteger result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } });
etherService.addTokenAddress( account, tokenAddress) .setCallback(new ListenableFutureTask.Callback<EthereumAccount>() { @Override public void onSuccess(final EthereumAccount account) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } });
etherService .callSmartContractFunction( account, toContractAddress, encodedFunction ) .setCallback(new ListenableFutureTask.Callback<String>() { @Override public void onSuccess(String result) { //success } @Override public void onFailure(ExecutionException exception) { //failure } @Override public void onCancelled(InterruptedException exception) { //cancelled } });
String checksumAddress = convertToChecksumAddress(ethAddress)