develop a blockchain shopping app objective create a shopping application with samsung blockchain platform sdk and pay using ethereum network overview the blockchain industry is expanding in many ways it is growing the most as a means of payment samsung blockchain platform sdk helps to make payments easily with cryptocurrency you can interact with blockchain through a simple api call to create a transaction in this code lab, you can pay for a product using the ethereum network in a simple shopping app, which is a decentralized application dapp dapps run and store data on the blockchain network instead of a central server set up your environment you will need the following java se development kit 8 or later android studio latest version recommended mobile phone with samsung blockchain sample code here is a sample code for you to start coding in this code lab download it and start your learning experience! platform sdk sample code 3 94 mb enable developer mode to activate developer mode on your mobile device, follow the steps below navigate through settings > biometrics and security > samsung blockchain keystore and click about blockchain keystore tap the samsung blockchain keystore app name quickly, ten times or more if succeeded, developer mode will show import project file open the downloaded sample code containing the shopping app project go to file > open and select the open file or project window every gui resources are already included in the provided project you simply need to fill out the code by following the next steps moreover, it is recommended to go through the documentations of samsung blockchain platform sdk initialize the instance create an sblockchain instance this is the first step since sblockchain is the initial base class of sdk along with that are hardwarewalletmanager responsible for wallet operations accountmanager responsible for account operations msblockchain = new sblockchain ; msblockchain initialize mcontext ; maccountmanager = msblockchain getaccountmanager ; mhardwarewalletmanager = msblockchain gethardwarewalletmanager ; mcoinnetworkinfo = new coinnetworkinfo cointype eth, ethereumnetworktype goerli, rpcurl ; connecttokeystore ; connect to samsung blockchain keystore you can get hardware wallet instance from hardwarewalletmanager hardwarewallettype refers to the type of cold wallet to be connected, such as samsung blockchain keystore and ledger nano s mhardwarewalletmanager connect hardwarewallettype samsung, false setcallback new listenablefuturetask callback<hardwarewallet> { @override public void onsuccess hardwarewallet hardwarewallet { handler post new runnable { @override public void run { log i tag,"hardwarewallet is connected successfully" ; mprogressbar setvisibility view invisible ; setaccountstatus ; } } ; } @override public void onfailure @notnull executionexception e { mprogressbar setvisibility view invisible ; e printstacktrace ; } @override public void oncancelled @notnull interruptedexception e { mprogressbar setvisibility view invisible ; e printstacktrace ; } } ; the second parameter of connect api refers to reset if you do not want to reset the wallet then keep it false, otherwise true manage your account now, your shopping dapp is connected to the keystore it means that if you have your own account with balance, you can now buy using ether or eth let’s create an ethereum account to be used for payment for generating a new account with samsung blockchain platform sdk you need an instance of the accountmanager from sblockchain accountmanager provides methods for fetching, creating, restoring accounts, and other more once you have an instance of accountmanager, you can call generatenewaccount as shown below it has methods regarding accounts such as get, create, and restore refer to the samsung blockchain platform sdk documentations for more details hardwarewallet connectedhardwarewallet = mhardwarewalletmanager getconnectedhardwarewallet ; if connectedhardwarewallet != null { try { maccountmanager generatenewaccount connectedhardwarewallet, mcoinnetworkinfo get ; } catch interruptedexception e { e printstacktrace ; } catch executionexception e { e printstacktrace ; } } if an account is already created, textview is shown at the top of the app and the create account button is disabled to prevent further account creation list<account> accounts = maccountmanager getaccounts null, cointype eth, ethereumnetworktype goerli ; if !accounts isempty { methereumaccount = ethereumaccount accounts get accounts size - 1 ; tvaccountstatus settext methereumaccount getaddress ; btncreateaccount setenabled false ; } get instance for ledger service after creating an account, you can use it for payment in your shopping dapp each coin blockchain ledgers has its own system to be stored in blocks samsung blockchain platform sdk provides abstracted api sets to developers for signing and sending supported cryptocurrency transactions over the blockchain network create coinservicefactory and just use any ledger you want in this scenario, use ethereumservice ethereumservice service = ethereumservice coinservicefactory getcoinservice mcontext, mcoinnetworkinfo ; at this point, your shopping dapp is ready to provide payment methods working on ethereum notebefore the next step, you need at least one valid ethereum account show payment sheet when a user selects an item, the app should show the payment screen it must show “who will pay how much amount of ether to whom” in the blockchain world, ethereum ledgers require more information, such as transaction nonce, to record that transaction into ledgers with samsung blockchain platform sdk, developers can do everything needed to show the payment sheet, intent should be created, which is to call the payment activity on click event of product object fill the parameters required and startactivityforresult to show a payment sheet item item = itemlist get position ; biginteger price = ethereumutils convertethtowei item getprice ; ethereumservice service = ethereumservice coinservicefactory getcoinservice mcontext, mcoinnetworkinfo ; hardwarewallet connectedhardwarewallet = mhardwarewalletmanager getconnectedhardwarewallet ; intent intent = service createethereumpaymentsheetactivityintent mcontext, connectedhardwarewallet, ethereumtransactiontype eip1559, methereumaccount, sample_to_adderss, price, null, null ; startactivityforresult intent, 0 ; get ether from faucet you need money when you buy something a free faucet site is provided to get ether if you have an ethereum account, just go to webview fragment and press send me eth button see the result of transaction if the payment was performed successfully from the payment screen, the result of transaction can be received from onactivityresult if the transaction is performed properly, you can find the result_ok at resultcode from the intent, a txid is shown which can be used to check your transaction’s status call gettransactiondetail txid string api method in ethereumservice and check the block# if there’s any valid countable number, your transaction is stored in blocks successfully and the payment is done if you can’t find it, just wait it’s processing among ethereum nodes alternatively, simply find the txid in goerli testnet explorer run the project you have created and verify that it works properly open the app and select the product from the list in the payment screen, select the fee to pay to the ethereum network and confirm the transaction then, check the result of the generated transaction sample images of the app screen can be seen below you're done! congratulations! you have successfully achieved the goal of this code lab now, you can develop a shopping dapp using samsung blockchain platform sdk by yourself! if you're having trouble, you may download this file platform sdk complete code 3 95 mb to learn more about developing apps with samsung blockchain, visit developer samsung com/blockchain