develop a secure blockchain app objective learn how to create your own decentralized applications dapp using samsung blockchain keystore sdk overview integrating with new technology like blockchain is a burden to most developers for this reason, we offer a way to interwork with samsung blockchain keystore sdk with less effort developers can easily become a dapp developer with our samsung blockchain keystore sdk decentralized applications dapps run and store data on the blockchain network instead of a central server dapps offer increased security and reliability compared to centralized applications moreover, it provides a simple method for in-app payments using cryptocurrency samsung blockchain keystore sdk is used to obtain account information and sign a transaction to transfer cryptocurrency or execute smart contract execution in this code lab, you can learn how to integrate samsung blockchain keystore sdk into your app and how to implement blockchain basic concepts such as account information and signing transactions set up your environment you will need the following java se development kit 8 or later android studio latest version recommended mobile phone which supports 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! keystore sdk sample code 897 12 kb enable developer mode the developer mode helps developers test the samsung blockchain keystore in developer mode, app id verification is bypassed, so samsung blockchain keystore apis will be enabled 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 noteonly a limited number of devices can be activated for one test app open project file after downloading the sample code, open the given android application project this project is a simple comments dapp based on ethereum ropsten test network it retrieves comments data from smart contract, displays them on the screen, and makes a transaction to execute smart contract function to post user’s comment in the next steps, you can get an account address and execute dapp service with blockchain keystore and you can see the result of successful dapp execution set the app id here, you don’t need to set the application id to use samsung blockchain keystore sdk instead, you must enable developer mode as described previously for the release version of your android app, in your android manifest file, add a metadata with a name as scw_app_id and a value as the app id issued by samsung blockchain keystore team samsung blockchain keystore aar file will read this value when your android app is initialized and help your android app connect to samsung blockchain keystore <manifest xmlns android="http //schemas android com/apk/res/android" package="com samsung android sdk coldwallet test" android versioncode="1" android versionname="1 0"> <application> <meta-data android name="scw_app_id" android value= <!-- put your app id here --> /> </application> </manifest> import samsung blockchain keystore sdk library into the project the sdk library is located at aar/keystoresdk_v1 5 1 aar of the project file to import the library go to gradle scripts > build gradle and enter the following dependencies dependencies { repositories { flatdir{ dirs 'aar' } } implementation 'com samsung android sdk coldwallet keystoresdk_v1 5 1@aar' } check the status of samsung blockchain keystore the first thing to do is to check the status of samsung blockchain keystore in the sample application, it is implemented at initializekeystore in presenter intropresenter java you can find the following steps to check the status of keystore in your android app, call scwservice getinstance if the returned value is an instance and not null, then it means samsung blockchain keystore is supported on the device however, if null is returned, the user must use a different keystore in the sample code, toast a message to notify that the device doesn’t support the keystore // check samsung blockchain keystore is supported or not if scwservice getinstance == null { mcontract toastmessage "samsung blockchain keystore is not supported on your device " ; } call getkeystoreapilevel api to see if the current samsung blockchain keystore being used, properly supports the features that your android app is currently aiming for if the required api level is higher than the current samsung blockchain keystore level, users are directed to samsung blockchain keystore app page in galaxy store through the provided deeplink to update // check installed api level else if scwservice getinstance getkeystoreapilevel < 1 { // if api level is lower, jump to galaxy apps to update keystore app mcontract showdialog "" , "ok" , "the api level is too low jump to galaxy store" , -> mcontract launchdeeplink scwdeeplink galaxy_store ; } check if a user has set up the samsung blockchain keystore and is ready to use it by calling getseedhash api if the seed hash value in string is zero-length, this means the user has not set up samsung blockchain keystore yet hence, your app will need to guide the user to jump to samsung blockchain keystore via deeplink to either create or import a wallet // check seed hash exist else if scwservice getinstance getseedhash length == 0 { // if seed hash is empty, // jump to blockchain keystore to create or import wallet mcontract showdialog "" , "ok" , "the seed hash is empty " + "jump to blockchain keystore to create/import wallet " , -> mcontract launchdeeplink scwdeeplink main ; } if the getseedhash api returned value is not zero-length, it means that the user has successfully set up samsung blockchain keystore if there is a previously saved or cached seed hash value, compare the two seed hash values if those two values are not equal, nor if there is no such saved cached seed hash value, then the address has to be checked again if the seed hash value has been changed, it means the master seed has been changed as well, meaning the address that your android app was linked to may no longer be the same address // check seed hash cached else if !textutils equals cachedseedhash, scwservice getinstance getseedhash { // if the seed hash is different from cached, update seed hash and address // go to next activity final string ethereumhdpath = "m/44'/60'/0'/0/0"; getethereumaddress ethereumhdpath , success, errorcode, address, seedhash -> { if success { updateaddress address ; updateseedhash seedhash ; mcontract showtimelineactivity true ; } else { mcontract toastmessage "cannot get address error code " + errorcode ; } mcontract setloading false ; } ; return false; } if those two values are equal, it means checking the keystore status was successful, and you can move on to the next step // success else { // set address from cached value // go to next activity string address = prefshelper getinstance getcachedaddress ; updateseedhash cachedseedhash ; updateaddress address ; mcontract showtimelineactivity false ; } get the ethereum address in the blockchain network, the address can be used like a user’s account as the balance and the transaction history can be checked using the address in this sample project, get the address from keystore and display the address and account balance in the bottom sheet of the screen keystore is a hierarchical deterministic hd wallet, a standard tree structure represented by derivation paths for the ethereum address, use “m/44'/60'/0'/0/0” follow bip44 it is implemented at getethereumaddress string hdpath, getethereumaddresscallback callback in presenter/intropresenter java arraylist<string> path = new arraylist<> ; path add hdpath ; scwservice getinstance getaddresslist new scwservice scwgetaddresslistcallback { @override public void onsuccess list<string> list { string seedhash = scwservice getinstance getseedhash ; string address = list get 0 ; callback onaddressreceived true, 0, address, seedhash ; } @override public void onfailure int errorcode, string errormessage { callback onaddressreceived false, errorcode, "", "" ; } }, path ; sign a transaction ether value transfer or smart contract execution is executed by transactions that users create and sign signing a transaction is the process of generating a signature on it using the private key of the transaction sender samsung blockchain keystore can be utilized to sign a cryptocurrency transaction, such as ethereum by implementing the following steps creates an unsigned transaction, and requests samsung blockchain keystore to sign the transaction via apis like signethtransaction then the user will see a transaction confirmation page on a secure screen called, trusted user interface tui executed in trusted execution environment tee by samsung blockchain keystore once the user confirms the transaction with pin or biometrics authentication, like fingerprint, samsung blockchain keystore will sign a transaction with the private key derived from the given hd path when samsung blockchain keystore returns the signed transaction, your app can submit or send the signed transaction to the blockchain network in this sample project, create an unsigned transaction to execute posting a comment smart contract in addition, sign the transaction with keystore and send the transaction it is implemented at signtransaction in presenter/writefeedpresenter java // sign the transaction with samsung blockchain keystore // use hdpath m/44'/60'/0'/0/0 final string hdpath = "m/44'/60'/0'/0/0"; scwservice getinstance signethtransaction new scwservice scwsignethtransactioncallback { @override public void onsuccess byte[] signedtransaction { boolean result = sendsignedtransaction signedtransaction ; listener transactiondidfinish result, "" ; } @override public void onfailure int errorcode, string errormessage { listener transactiondidfinish false, "error code " + errorcode ; } }, unsignedtx, hdpath, null ; run the app and try it out the app screen should look like below you're done! congratulations! you have successfully achieved the goal of this code lab now, you can create a decentralized app by yourself! if you're having trouble, you may download this file keystore sdk complete code 897 07 kb