Quantcast
Jump to content


Step into the Decentralized Blockchain Future with Samsung Blockchain Ecosystem


Recommended Posts

2021-09-21-01-banner.jpg

SDKs for Blockchain Developers

At Samsung, we understand that one size does not fit all of your development needs. That’s why we offer two different SDKs to cover your blockchain development needs: Samsung Blockchain Platform (SBP) SDK and Samsung Blockchain Keystore (SBK) SDK. The SBP SDK aims to be an overall solution for your DApp’s every need, from connecting to supported hardware wallets to uploading transactions in the supported Blockchain networks. On the other hand, the SBK SDK allows you to securely access the Samsung Blockchain Keystore cold wallet and supports signing transactions of a wide range of cryptocurrencies.

Samsung Blockchain Platform SDK

The Samsung Blockchain Platform SDK offers a full set of functions for your Decentralized App (DApp) or Blockchain App needs. It helps you manage blockchain accounts easily and make a transaction easier by using abstracted transfer APIs. Additionally, the SBP SDK offers a UI-based cryptocurrency payment solution for even more rapid development.

2021-09-21-01-01_v2.jpg

The Samsung Blockchain Platform SDK can easily connect your DApp to different hardware wallets for securely signing transactions. Currently, three hardware wallets are supported: Samsung Blockchain Keystore, Ledger Nano X, and Ledger Nano S. Once successfully connected to a hardware wallet, the SBP SDK offers abstracted APIs, so you never have to worry about what hardware wallet to which the user is connected.

The SBP SDK also has a blockchain browser solution for your web DApp. With the SBP SDK’s Cucumber Webview, you can migrate your web-based DApp into the mobile environment with little to no changes in your web app. This can help you drastically reduce development time and resources, and to reach millions of new Galaxy devices.

With the SBP SDK’s Payment Sheet UI, developing a native Android DApp has never been easier. Simply launch the desired Payment Sheet Intent and let the SDK take care of the rest of your DApp’s payment or transfer flows.

2021-09-21-01-02.jpg

The SBP SDK currently supports two major Blockchain networks: Ethereum and TRON. With the SBP SDK’s abstracted APIs for cryptocurrency and token transfers, you never have to worry about complex details. The SBP automatically estimates transaction fees and handles code for underlying smart contract function ABIs for token transfer. You can simply plug in your JSON-RPC endpoint/node to the SBP and develop your DApp faster.

You can check out all of the aforementioned APIs (and more) in action, on the Aero Wallet sample application for the SBP SDK. Using Aero Wallet’s source code, you can learn how to easily build a fully functional cryptocurrency wallet application from scratch. To learn more about how the SBP SDK can greatly simplify your DApp development, check out the SDK Overview.

Samsung Blockchain Keystore SDK

The Samsung Blockchain Keystore, powered by the Knox Security Platform, is a built-in secure cold wallet available on a wide range of Galaxy devices. The Samsung Blockchain Keystore SDK allows your Android apps and DApps to communicate directly with this highly secure cold wallet for fetching address lists and public keys and signing cryptocurrency transactions.

2021-09-21-01-03.jpg

With the SBK SDK, your DApp can fetch the user’s blockchain address and link it to the user’s account. Using this address, you can query on the blockchain network (using a blockchain explorer or another library such as SBP) to find the user’s account balance and transaction history.

Furthermore, you can use the SBK SDK to request the Keystore app to sign a cryptocurrency transaction. The Keystore app then shows the requested transaction to the user inside a Trusted User Interface (TUI), executed within the Trusted Execution Environment (TEE). Once the user approves the transaction with a PIN or a biometric authentication like a fingerprint, the Keystore app signs the transaction with the associated private key and returns it to you through the SBK SDK.

To learn more about how you can integrate the SBK SDK into your app, check out the SDK overview.

Choosing the right SDK for your Dapp

Both of the Samsung Blockchain SDKs can help make your DApp more feature-rich and cut down development time and effort. If you are still confused about which SDK is best for your DApp, check out our brief comparison below.

API Samsung Blockchain Platform SDK Samsung Blockchain Keystore SDK
Fetch Public Address Supported Supported
Sign Transaction Supported Supported
Send Transaction Supported Unsupported
Send Token Transaction Supported Unsupported
Built-in Payment Screen UI Supported Unsupported
Seamless Integration with WebApps Supported Unsupported
External Hardware Wallet Supported Unsupported
Blockchain Networks Supported (at the time of writing) Ethereum and Tron Bitcoin, Ethereum, Klaytn, Stellar and Tron

Services for End-Users

Samsung Blockchain Apps and services aim to provide you with a secure and convenient experience in the blockchain world. Samsung currently offers two applications under its blockchain platform: the Samsung Blockchain Keystore app and the Samsung Blockchain Wallet app. You can find out more about each of these offerings from this article and from the global Samsung site.

Samsung Blockchain Keystore

Samsung Blockchain Keystore offers defense-grade, vault-like security for your crypto assets. The Blockchain Keystore app runs within the TEE of the Knox Platform. This allows the Samsung Blockchain Keystore to provide security unlike ever before, as the private key and information located in the Samsung Blockchain Keystore are never saved to a Samsung or an external cloud, nor is it seen by the devices’ Android OS.

2021-09-21-01-04.jpg

You can easily set up the Keystore app by importing your existing account by using a 12-word mnemonic, or create an entirely new one.

2021-09-21-01-05.jpg

2021-09-21-01-06.jpg

2021-09-21-01-07.jpg

2021-09-21-01-08.jpg

Samsung Blockchain Wallet

The Samsung Blockchain Wallet app allows you to conveniently send and receive major cryptocurrencies such as Bitcoin and Ether. Not only does the Samsung Blockchain Wallet app support the built-in Samsung Blockchain Keystore wallet, it also supports external physical wallets such as Ledger Nano S and Nano X, using USB.

2021-09-21-01-09.jpg

2021-09-21-01-10.jpg

2021-09-21-01-11.jpg

2021-09-21-01-12.jpg

Beyond sending and receiving crypto assets, you can also explore partner DApps through the Blockchain Wallet App. Partner DApps on the Samsung Blockchain Wallet app unlock the door to a wide range of experiences such as cryptocurrency exchanges, staking pools, and NFT marketplaces. Furthermore, you can stay on top of the latest trends and ongoing events in the blockchain world with the Samsung Blockchain Wallet’s News section.

2021-09-21-01-13.jpg

2021-09-21-01-14.jpg

Conclusion

Blockchain technology has the potential to revolutionize many aspects of our lives. With Samsung Blockchain SDKs and applications, you and your DApp users can always stay at the forefront of this technology. We want to continuously improve your experience in the blockchain world. Feel free to share your thoughts with us and with the global blockchain developer community on the Samsung Blockchain Developer forum.

View the full blog at its source

Link to comment
Share on other sites



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By Samsung Newsroom
      TRON is a well-known, blockchain-based, and decentralized platform that aims to create a global decentralized digital content system. By using blockchain technology, TRON has established a network between content creators and consumers, which eliminates the need for a middleman between these two parties.
      Because TRON is an account-based blockchain system, a transaction in TRON is executed by an account and every transaction needs to pass the consensus process, which is known as DPoS. In this process, some witnesses are selected according to a vote to verify the transaction. Any token holder can vote to select these witnesses.
      The Samsung Blockchain Platform (SBP) SDK provides an opportunity for Android developers to develop applications that can interact with Ethereum and TRON blockchain platforms. The SBP SDK supports coin transactions as well as smart contracts and tokens like TRC-10, TRC-20, and so on.
      This blog describes the process of sending TRX (the base coin of the TRON platform) using the SBP SDK, with a sample application. For an example of sending Ether (the base coin of the Ethereum platform), see Send Ether with Samsung Blockchain Platform SDK.
      Prerequisites
      For developing a sample application that can perform TRX transactions, the following actions must be performed before the transaction takes place.
      Initialize the object Connect to a hardware wallet Get accounts Each of these actions of the application has been implemented with a corresponding button so that the results of each action can be more visible and clearly illustrated.

      Initialize the object
      To use the APIs of the SDK in an Android project, an object of the SDK is required. To create the object, follow the steps below.
      Create a new Android project and integrate the SBP SDK with the application. All dependencies need to be mentioned in the build.gradle file. To complete this step follow these instructions. After completing the synchronization of build.gradle with the file system, the project is ready for creating an instance of the Sblockchain class. Relevant source code can be found here. Connect to a hardware wallet
      A hardware wallet is a storage device with the facility of authentication for securely storing the public-private key pair. There are several hardware wallets in the market, and Samsung provides a hardware wallet integrated with select Samsung mobile devices, known as the Samsung Blockchain Keystore.
      SBP provides an interface to connect hardware wallets. Alongside the Samsung Blockchain Keystore, SBP currently supports Ledger Nano X and Ledger Nano S. Connect your application with a hardware wallet using the following code.
      In this article, the Samsung Blockchain Keystore has been used as the hardware wallet. While running the sample application on your device, please ensure you meet the device restrictions of the Samsung Blockchain Keystore. You can also change the hardware wallet type and test the same application with other supported hardware wallets.
      Get accounts
      An account is an important protocol of TRON. It functions as a gateway to interact with the TRON blockchain. Your TRX balance, token balance, bandwidth, energy, and so on are all attached to your account. TRX balance can be sent from one account to another. Moreover, an account can issue a smart contract. TRON accounts also provide the facility to vote for super representatives. To learn more about super representatives and voting, see the TRON documentation.
      Every account consists of a private and public key pair. An account remains deactivated until a TRX or token transaction is performed. Creating an account consumes frozen bandwidth points. If none are available, then the action burns 0.1 TRX instead. If you want to know more about the underlying algorithm and the process of creating an account, see the TRON account documentation.
      The SBP SDK allows you to create a new account or restore existing accounts from the TRON network. Restoring and creating accounts are network operations. For more information, see the account management guide for the SBP SDK. It discusses generating, restoring and fetching accounts using the SDK.
      If you have no TRX in your account, you can get some by purchasing from the sites listed here or get test TRX.
      TRX Transaction
      Let's send TRX from your account to another account. The SBP SDK provides an API called sendTransaction to perform a transaction between two accounts. This API needs four parameters.
      wallet: A connected hardware wallet. fromAccount: The sender’s TRON account. toAddress: Where you want to transfer your TRX to, taking the address as a string. value: How much TRX you want to transfer. Input unit is SUN (1 TRX= 10^6 SUN). The CoinService class called TronService provides the sendTransaction API for transactions on the TRON platform. In addition, a Remote Procedure Call (RPC) is required to communicate with the TRON node. We are going to use TronGrid for this purpose, which allows developers to access a TRON client that is running on the cloud instead of creating one. You can learn more about the TronGrid here.
      Before completing the example transaction, some terminology related to transactions, like bandwidth and energy, are discussed.
      NetworkType networkType = TronNetworkType.SHASTA; CoinType coinType = CoinType.TRX; //Shasta rpc String rpc = "https://api.shasta.trongrid.io"; // creating coinNetworkInfo CoinNetworkInfo mCoinNetworkInfo = new CoinNetworkInfo(coinType, networkType, rpc); //Creating CoinService CoinService mCoinService = CoinServiceFactory.getCoinService(getApplicationContext(), mCoinNetworkInfo); //Creating TronService TronService tronService = (TronService) mCoinService; Fetch TRX balance
      TRX is the primary currency of TRON. It can be used to obtain Bandwidth, Energy, or Power. The SBP SDK provides the getBalance API for fetching the balance of an account.
      public void onClickGetBalance(View view) { mCoinService = CoinServiceFactory.getCoinService(getApplicationContext(), mCoinNetworkInfo); TextView trxAmountTextView = findViewById(R.id.amount_tron); mCoinService.getBalance(mFirstAccount).setCallback(new ListenableFutureTask.Callback<BigInteger>() { @Override public void onSuccess(BigInteger bigInteger) { convertedAmount = TronUtils.convertSunToTrx(bigInteger); Log.i(LOG_TAG, "Balance has fetched successfully."); Log.i(LOG_TAG, "Balance is:" + convertedAmount.toString()); runOnUiThread(() -> { accountInfoButton.setEnabled(true); trxAmountTextView.setText(convertedAmount.toString()); } ); } @Override public void onFailure(@NotNull ExecutionException e) { Log.e(LOG_TAG, "Fetching balance is failed."); Log.e(LOG_TAG, "" + e.getMessage()); } @Override public void onCancelled(@NotNull InterruptedException e) { Log.e(LOG_TAG, "Fetching balance is canceled."); } }); } Fetch bandwidth and energy
      TRON implements some new and interesting features named freeze, bandwidth, and energy. You can freeze some of your TRX balance to gain bandwidth and energy. For every frozen TRX, the user receives 1 TRON power which is needed to cast a vote on super representatives. After freezing some of your TRX, it is not possible to use these TRX until they are unfrozen.
      Bandwidth is used as a fee for TRX transactions. Energy is needed to execute smart contracts. The SBP SDK only provides an API to get a frozen balance amount. You can freeze TRX and gain bandwidth and energy using Tronscan. Tronscan is a blockchain explorer, which allows anyone to explore addresses, transactions, and tokens in the TRON blockchain.
      The SBP SDK provides the getAccountInfo API for fetching bandwidth, energy and power (frozen balance) information. The input parameter is the account address of the sender. In the sample application, after pressing the Account Info button, the asynchronous task returns this information, which is set on a text view in the UI.
      public void OnClickAccountInfo(View view) { tronService = (TronService) mCoinService; try { tronService.getAccountInfo(mFirstAccount.getAddress()).setCallback(new ListenableFutureTask.Callback<TronAccountInfo>() { @Override public void onSuccess(TronAccountInfo tronAccountInfo) { Log.i(LOG_TAG, "Account info is fetched successfully."); Log.i(LOG_TAG, "BandWidth is:" + tronAccountInfo.getBandwidth()); Log.i(LOG_TAG, "Power is:" + tronAccountInfo.getFrozenBalance()); runOnUiThread(() -> { sendButton.setEnabled(true); bandWidthTextView.setText(tronAccountInfo.getBandwidth().toString()); powerTextView.setText(tronAccountInfo.getFrozenBalance().toString()); } ); } @Override public void onFailure(@NotNull ExecutionException e) { Log.e(LOG_TAG, "Fetching account info is failed."); Log.e(LOG_TAG, "" + e.getMessage()); } @Override public void onCancelled(@NotNull InterruptedException e) { Log.e(LOG_TAG, "Fetching account info is canceled."); } }); } catch (Exception e) { Log.e(LOG_TAG, "Error in fetching account info: " + e); } } After fetching bandwidth and energy, we can check them on the sample application UI.

      Transfer TRX
      Now we have all the parameters needed for sending TRX. The sendTransaction API is used to transfer TRX to the recipient. If the transaction is successful, the onSuccess() callback returns the transaction hash.
      Every transaction in the TRON blockchain can be found in Tronscan.
      public void onClickSend(View view) { if (toAddress.isEmpty() || amount.isEmpty()) { Toast.makeText(getApplicationContext(), "Fill ToAddress and Amount Field", Toast.LENGTH_SHORT).show(); } else if(!tronService.isValidAddress(toAddress)){ Toast.makeText(getApplicationContext(), "Invalid Address.", Toast.LENGTH_SHORT).show(); } else { BigDecimal sendAmount = new BigDecimal(amount); BigInteger convertedSendAmount = TronUtils.convertTrxToSun(sendAmount); try { tronService.sendTransaction(mHardwareWallet, (TronAccount) mFirstAccount, toAddress, convertedSendAmount).setCallback(new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult transactionResult) { Log.d(LOG_TAG, "Transaction Hash: " + transactionResult.getHash()); runOnUiThread(() -> Toast.makeText(getApplicationContext(), "Transaction Hash: " + transactionResult.getHash(), Toast.LENGTH_SHORT).show() ); } @Override public void onFailure(@NotNull ExecutionException e) { Log.e(LOG_TAG, "Transaction failed."); Log.e(LOG_TAG, "" + e.getMessage()); } @Override public void onCancelled(@NotNull InterruptedException e) { Log.e(LOG_TAG, "Transaction canceled."); } }); } catch (AvailabilityException e) { Log.e(LOG_TAG, "Error in sending: " + e); } } } Now that you can send TRX to another account, you can create your wallet application and implement a transfer function using the SBP SDK. Keep an eye on the Samsung Developers site for updates as the Samsung Blockchain keeps expanding support for new platforms.
      Additional Resources:
      Download the SBP SDK Transaction Sample App More Information on the SBP SDK Follow Up
      This site has many resources for developers looking to build for and integrate with Samsung devices and services. Stay in touch with the latest news by creating a free account or by subscribing to our monthly newsletter. Visit the Marketing Resources page for information on promoting and distributing your apps. Finally, our developer forum is an excellent way to stay up-to-date on all things related to the Galaxy ecosystem.
      View the full blog at its source
    • By Samsung Newsroom
      Start Date Sep 18, 2020
      Location South Korea
      [Eng]
      Greetings from the Samsung Blockchain OPS team!
      We are pleased to be co-hosting the 2020 JEJU Blockchain Hackathon alongside JEJU Creative Economy Innovation Center, GroundX, and KaKao.
      The Hackathon challenges students, new graduates, startups (or pre-startups) to develop blockchain-based services.
      The event is a platform for participants to turn their ideas into reality through developing a prototype, enhancing their problem solving skills, and networking with and learning about blockchain-based platform services. The Business Camp program also enables participants to receive mentoring and support to launch their blockchain-based services.
      Note: The event is open to participants in Korea only.
      Title: 2020 JEJU Blockchain Hackathon Date: 31 August - 25 October, 2020 Theme: Developing blockchain-based services and applications, with special consideration for those implementing the Klaytn API Service (KAS) or the Samsung Blockchain SDKs (Keystore/Platform) Program Highlights: Online Hackathon (18-20, September), Business Camp (23 - 25 October, in-person) Hosts: JEJU Creative Economy Innovation Center, GroundX, Samsung, KaKao Join us!
      For more information: links



      [국문]
      안녕하세요. 삼성 블록체인 운영 팀입니다.
      이번에 저희가 제주창조경제혁신센터, 그라운드X, 카카오와 함께 주최하는 제 3회 제주 블록체인 해커톤 행사를 전할 수 있게 되어 기쁩니다.
      블록체인 기술 기반 서비스 개발에 관심있는 누구나 참여가 가능하며, 2020 제주 블록체인 해커톤 공식사이트에서 신청할 수 있으니 많은 분들의 신청 부탁드립니다. 심사를 거쳐 선발된 팀은 2020년 9월 18일부터 20일까지 3일간 온라인으로 해커톤에 참여하게 되며, 심사위원 평가를 통해 최종 4개의 팀이 선발되어 총 400만원의 상금과 제주에서 예정된 비즈니스 캠프 참여 기회가 주어집니다.
      행사명 : 2020 제주 블록체인 해커톤 행사기간 : 8월 31일부터 10월 25일까지 주제 : 블록체인 기술과 토큰 이코노미를 적용한 블록체인 어플리케이션 개발 (그라운드X Klaytn API Service(KAS) 또는 삼성 블록체인 SDKs 사용시 가산점 부여) 주요 프로그램 : 온라인 해커톤 (9월 18일~20일), 비즈니스 캠프 (10월 23일~25일, 오프라인 진행) 주관/주최 : 제주창조경제혁신센터, GroundX, 삼성전자, 카카오 더 자세한 사항 확인 및 지원 하러 가기 links




      View the full blog at its source
    • By Samsung Newsroom
      Blockchain, an emerging technology, is a distributed database for storing and managing records of transactions. It has already created a huge impact in the financial sector.
      The transaction is the main feature in any blockchain-based system. In Ethereum, one of the better-known blockchain systems, every transaction is executed by either an account or a smart contract. When an account tries to execute a transaction, it creates one and publishes it in the Ethereum blockchain. Every transaction needs to pass the consensus process. Some nodes in the Ethereum blockchain, known as miners, validate and authenticate the transaction. “Gas” is an incentive that is paid out for executing transactions. On the Ethereum platform, gas is paid to miners for completing the consensus process.
      The Samsung Blockchain Platform SDK enables Android developers to develop applications that interact with the Etherum blockchain platform. In addition to transactions, the Samsung Blockchain Platform SDK also supports operations related to smart contracts and tokens.
      Through a sample application, this blog describes how to use the Samsung Blockchain Platform SDK to transfer Ether, which is the base coin for the Ethereum platform.
      Prerequisites
      Before the application can make a transaction, it must first perform the following actions in order:
      Initialize and create the instance Connect to the hardware wallet Get the account Let’s associate each of these actions with a button in our sample application.


      1. Initialize and create the instance
      In the Android project, integrate the Samsung Blockchain Platform SDK with the application and mention all the dependencies in build.gradle. Next, create an instance of the Sblockchain class.
      2. Connect to the hardware wallet
      The Samsung Blockchain Platform provides an interface to connect to hardware wallets, which are special devices that securely store private keys. Samsung mobile devices have an integrated hardware wallet, the Samsung Blockchain Keystore. Besides the Samsung Blockchain Keystore, the Samsung Blockchain Platform also supports USB-connected Ledger devices and BLE-connected Nano X devices.
      The sample application connects to the Samsung Blockchain Keystore hardware wallet. Before you run the sample application on your device, check that the device is supported. You can also modify the sample application and test it with other supported hardware wallets.
      3. Get the account
      An account is a gateway for interacting with the Ethereum blockchain. Each account consists of a private and public key pair, for which the shortened public key is the account address. Every initial action in the Ethereum blockchain must be initiated by an account.
      The Samsung Blockchain Platform SDK enables the user to create a new account or to restore their accounts from the Ethereum network. Account management features in the Samsung Blockchain Platform SDK include generating, restoring and fetching accounts. Because they are network operations, the create account and restore accounts operations must perform asynchronously.
      After creating a new account, the user must utilize the account to receive or send Ether before the Samsung Blockchain Platform SDK allows them to create another account.
      If you do not have any Ether to use with the sample application, you can use test Ether.

      Performing Ether Transactions
      The sendTransaction API of the Samsung Blockchain Platform SDK initiates a transaction between two accounts. It requires the following information in its parameters:
      wallet: connected hardware wallet fromAccount: sender’s Ethereum account address gasPrice: price of each gas unit, which defines how quickly someone wants to execute the transaction gasLimit: maximum number of gas units to spend on the transaction toAddress: recipient’s Ethereum account address value: amount of Ethereum to transfer, in wei (1 eth = 10^18 wei). nonce: transaction counter for the account. The CoinService class named EthereumService provides methods needed to create transactions on the Ethereum platform. For example, the getFeeInfo() and estimateGasLimit() methods can retrieve the values for use with the gasPrice and gasLimit parameters, respectively.
      To communicate with the Ethereum node, RPC is also needed. In the sample application, the Infura node is used to access the Ethereum blockchain. Learn about integrating the Infura API with the JSON RPC.
      CoinType coinType = CoinType.ETH; NetworkType networkType = (NetworkType) EthereumNetworkType.ROPSTEN; //might use your own rpc String rpc = "https://ropsten.infura.io/v3/71cf9f88c5b54962a394d80890e41d5b"; // creating coinNetworkInfo CoinNetworkInfo mCoinNetworkInfo = new CoinNetworkInfo(coinType, networkType, rpc); //Creating CoinService CoinService mCoinService = CoinServiceFactory.getCoinService (getApplicationContext(), mCoinNetworkInfo); //Creating EthereumService EthereumService ethereumService = (EthereumService) mCoinService; //Access TextView and EditTexts on UI private RadioGroup transactionSpeedGroup = findViewById(R.id.transaction_speed_radio_group); private TextView gasLimitText = findViewById(R.id.gas_limit_text_view); private EditText toAddressEditText = findViewById(R.id.to_address); private EditText sendAmountEditText = findViewById(R.id.send_amount); Retrieve the gas price
      Gas price retrieval is an asynchronous task. Use the getFeeInfo API to retrieve the gas price. The getFeeInfo API returns three gas prices which depend on the speed of the transaction: fast, normal, and slow.
      To give full control over the gas price for advanced users, you can also enable numerical price input.
      In the sample application, when the user selects Gas Price, an asynchronous task retrieves the three gas prices, and assigns them to radio buttons. The user can select the transaction speed they want based on the gas price.
      public void OnClickGasPrice(View view) { ethereumService = (EthereumService) mCoinService; ethereumService.getFeeInfo().setCallback(new ListenableFutureTask.Callback<EthereumFeeInfo>() { @Override public void onSuccess(EthereumFeeInfo ethereumFeeInfo) { convertedAmount = EthereumUtils.convertWeiToGwei(ethereumFeeInfo.getNormal()); Log.i(LOG_TAG, "Fee info is fetched successfully."); mEthereumFeeInfo = ethereumFeeInfo; runOnUiThread(() -> { gasLimitButton.setEnabled(true); Toast.makeText(getApplicationContext(), "Fee info is fetched successfully.", Toast.LENGTH_SHORT).show(); } ); } @Override public void onFailure(@NotNull ExecutionException e) { Log.e(LOG_TAG, "Fetching Fee info is failed."); Log.e(LOG_TAG, "" + e.getMessage()); } @Override public void onCancelled(@NotNull InterruptedException e) { Log.e(LOG_TAG, "Fetching Fee info is canceled."); } }); } Fetching the gas limit
      Fetching the gas limit is also an asynchronous task. Use the estimateGasLimit API to calculate the gas limit. The input parameters are the account addresses of the sender and the receiver, the amount of Ether (in wei units), and the data to be sent.
      The sample application sends only Ether, so the data field is null. When the user selects Gas Limit, the gas limit is determined and shown on the screen.
      public void onClickGasLimit(View view) { String toAddress = toAddressEditText.getText().toString(); String amount = sendAmountEditText.getText().toString(); if (toAddress.isEmpty() || amount.isEmpty()) { Toast.makeText(getApplicationContext(), "Fill Send Address and Amount Field", Toast.LENGTH_SHORT).show(); } else if(!ethereumService.isValidAddress(toAddress)){ Toast.makeText(getApplicationContext(), "Invalid Address.", Toast.LENGTH_SHORT).show(); } else { BigDecimal sendAmount = new BigDecimal(amount); BigInteger convertedSendAmount = EthereumUtils.convertEthToWei(sendAmount); ethereumService.estimateGasLimit((EthereumAccount) mFirstAccount, toAddress, convertedSendAmount, null).setCallback(new ListenableFutureTask.Callback<BigInteger>() { @Override public void onSuccess(BigInteger bigInteger) { mGasLimit = bigInteger; Log.i(LOG_TAG, "Gas limit is fetched successfully."); Log.i(LOG_TAG, "Gas limit is:" + bigInteger.toString()); runOnUiThread(() -> { sendButton.setEnabled(true); gasLimitText.setText(bigInteger.toString()); }); } @Override public void onFailure(@NotNull ExecutionException e) { Log.e(LOG_TAG, "Fetching Gas limit is failed."); Log.e(LOG_TAG, "" + e.getMessage()); } @Override public void onCancelled(@NotNull InterruptedException e) { Log.e(LOG_TAG, "Fetching Gas limit is canceled."); } }); } }
      Send the Ether
      All the parameter values needed to send the Ether are now known. Use the sendTransaction API to initiate the transaction.
      In the sample application, the value of the nonce parameter has not been set manually. By leaving the value null, the platform handles the nonce value itself. If the transaction is successful, the onSuccess() event handler returns the transaction hash.
      A record of every Ethereum transaction is viewable in Etherscan, a blockchain explorer. It allows anyone to explore addresses, transactions, and tokens in the Ethereum blockchain.
      public void onClickSend(View view) { String toAddress = toAddressEditText.getText().toString(); BigDecimal sendAmount = new BigDecimal(sendAmountEditText.getText().toString()); BigInteger convertedSendAmount = EthereumUtils.convertEthToWei(sendAmount); //Getting Gas Price int transactionSpeedID = transactionSpeedGroup.getCheckedRadioButtonId(); if (transactionSpeedID == -1) { Toast.makeText(getApplicationContext(), "Select a Transaction Speed.", Toast.LENGTH_SHORT).show(); } else { switch (transactionSpeedID) { case R.id.transaction_speed_slow: mGasPrice = mEthereumFeeInfo.getSlow(); Log.d(LOG_TAG, "GasPrice: " + mGasPrice); break; case R.id.transaction_speed_normal: mGasPrice = mEthereumFeeInfo.getNormal(); Log.d(LOG_TAG, "GasPrice: " + mGasPrice); break; case R.id.transaction_speed_fast: mGasPrice = mEthereumFeeInfo.getFast(); Log.d(LOG_TAG, "GasPrice: " + mGasPrice); break; } } if(transactionSpeedID != -1) { try { ethereumService.sendTransaction(mHardwareWallet, (EthereumAccount) mFirstAccount, mGasPrice , mGasLimit, toAddress, convertedSendAmount, null).setCallback(new ListenableFutureTask.Callback<TransactionResult>() { @Override public void onSuccess(TransactionResult transactionResult) { Log.d(LOG_TAG, "Transaction Hash: " + transactionResult.getHash()); runOnUiThread(() -> Toast.makeText(getApplicationContext(), "Transaction Hash: " + transactionResult.getHash(), Toast.LENGTH_SHORT).show() ); } @Override public void onFailure(@NotNull ExecutionException e) { Log.e(LOG_TAG, "Transaction failed."); Log.e(LOG_TAG, "" + e.getMessage()); } @Override public void onCancelled(@NotNull InterruptedException e) { Log.e(LOG_TAG, "Transaction canceled."); } }); } catch (AvailabilityException e) { Log.e(LOG_TAG, "Error in sending: " + e); } } } Conclusion
      This blog has demonstrated how you can send Ether to another account, an example of a feature you can implement in a wallet application using the Samsung Blockchain Platform SDK.
      Check the Samsung Developers site periodically for updates as Samsung Blockchain Platform SDK keeps expanding support for new platforms.
      Additional Resources:
      Samsung Blockchain Platform SDK Transaction Sample Application Samsung Blockchain Platform SDK documentation View the full blog at its source





×
×
  • Create New...