Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Web3E Development Framework

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use the Web3E development framework". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Web3E, that is, Web3 for Embedded, is a full-function Web3 development framework for Arduino embedded devices, and the development language is CumberCraft +. Web3E can help embedded device developers quickly realize the Internet of things / IoT devices that can access the Ethernet block chain, which opens a new door for Internet of things developers.

1. Introduction to Web3E

Web3E is mainly tested on ESP32, and ESP8266 works properly. Web3E also includes a rapid development DApp injector that can easily convert your embedded device into ethernet Apps.

The development of Web3E began with a simple requirement: to develop an access control DApp that can run on ESP32. After going through quite a few setbacks during this period, we realized that we needed a way to simplify the development of DApp for networked embedded devices, which was the original motivation for developing Web3E.

The main features of Web3E include:

Support for TokenScript interface

The out-of-the-box ethernet square DApp injector can immediately transform the Internet of things embedded devices into ethernet DApp Apps that support ECDSA cryptography.

Implementation of optimized and simplified cryptographic algorithm

The trading system has been fully optimized, and both ERC20 and ERC875 contracts in Taifang have been used in practice.

2. Web3E installation

It is recommended that you use Platformio to install Web3E, because Web3E is already part of the Platformio development library, so there is no need to clone the original Web3E code base.

Using Web3E is easy, just create a new project in Platformio, and then modify the platformio.ini by referring to the following:

[env:esp32dev] platform = espressif32board = esp32devframework = arduino; Serial Monitor optionsmonitor_speed = 115200lib_deps = # Using a library name Web3E3, Web3E examples and usage

There are 4 sample applications of Internet of things + Ethernet Square preset in Web3E:

Simple DApp: shows how to create a DApp that can run on an embedded device. The onboard cryptography engine can fully interact with user input, and the public key recovery and signature verification on ESP32 can be completed in milliseconds.

Query wallet balance: show how to query ERC20 token balance and heterogeneous pass (NFT) balance on embedded devices

Transaction broadcast: show how to transfer ERC20 and ERC875 tokens on embedded devices

Ethernet currency transfer: shows how to achieve Ethernet currency transfer on embedded devices

For example, the following code shows how to use Web3E to get an Internet of things embedded device to support etheric currency transfers:

/ / Setup Web3 and Contract with Private Key...Contract contract (& web3, ""); contract.SetPrivateKey (PRIVATE_KEY); uint32_t nonceVal = (uint32_t) web3.EthGetTransactionCount (& address); / / obtain the next nonceuint256_t weiValue = Util::ConvertToWei (0.25,18); / / send 0.25 ethunsigned long long gasPriceVal = 100000000ULLint32Secrett gasLimitVal = 90000X string emptyString = ""; string toAddress = "0xC067A53c91258ba513059919E03B81CF93f57Ac7" String result = contract.SendTransaction (nonceVal, gasPriceVal, gasLimitVal, & toAddress, & weiValue, & emptyString)

The following code uses Web3E to query the Ethernet balance of the specified Ethernet Square address on the Internet of things embedded device:

/ / obtain balance in Weiuint256_t balance = web3.EthGetBalance (& address); / / get string balance as Eth (18 decimals) string balanceStr = Util::ConvertWeiToEthString (& balance, 18)

It is a bit more complicated to use Web3E to make embedded devices support the sending of ERC20 tokens, but considering that this is using Cpicard Cellular token, it is also acceptable:

String contractAddr = "0x20fe562d797a42dcb3399062ae9546cd06f63280"; Contract contract (& web3, contractAddr.c_str ()); contract.SetPrivateKey (); / / Get contract namestring param = contract.SetupContractData ("name ()", & addr); string result = contract.ViewCall (& param); string interpreted = Util::InterpretStringResult (web3.getString (& result). C_str ()); Serial.println (interpreted.c_str ()); / / Get Contract decimalsparam = contract.SetupContractData ("decimals ()", & addr); result = contract.ViewCall (& param) Int decimals = web3.getInt (& result); Serial.println (decimals); unsigned long long gasPriceVal = 22000000000ULLX uint32ontt gasLimitVal = 4300000; note we use decimal value obtained earlieruint256_t weiValue = Util::ConvertToWei (0.1, decimals); / / get nonceuint32_t nonceVal = (uint32_t) web3.EthGetTransactionCount (& addr); string toAddress = "0x007bee82bdd9e866b2bd114780a47f2261c684e3"; string valueStr = "0x00"; / / Setup contract function call string p = contract.SetupContractData ("transfer (address,uint256)", & toAddress, & weiValue) / / push transaction to ethereumresult = contract.SendTransaction (nonceVal, gasPriceVal, gasLimitVal, & contractAddr, & valueStr, & p); string transactionHash = web3.getString (& result); this is the end of the introduction of "how to use the Web3E development framework". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report