I connected esp32 WROOM-32D to web3 with this library. https://github.com/kopanitsa/web3-arduino
I tested the eth_send example of that library with both Arduino Ide and Platformio
After connecting to the Wifi the exception is like that
[SETUP] WAIT 4...
[SETUP] WAIT 3...
[SETUP] WAIT 2...
[SETUP] WAIT 1...
.Connected
abort() was called at PC 0x40162ff7 on core 1
Backtrace:0x40162ff7:0x3ffb23d00x4008cd21:0x3ffb23f0 0x40091ed1:0x3ffb2410
0x40162ff7:0x3ffb2490 0x4016303e:0x3ffb24b0 0x40154283:0x3ffb24d0 0x40153d92:0x3ffb24f0
0x40155275:0x3ffb2510 0x4015551d:0x3ffb2530
0x400dddef:0x3ffb2560 0x400de337:0x3ffb2580 0x400d293a:0x3ffb2610 0x400d2ada:0x3ffb27f0
0x400e0366:0x3ffb2820
I decoded the error exception with ESP exception Decoder and the error was decoded like this
Decoding stack results
0x400836f5: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c line 402
0x4008cd21: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/esp_system.c line 128
0x40091ed1: abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/abort.c line 46
0x40162ff7: __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc line 47
0x4016303e: std::terminate() at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc line 57
0x40154283: __cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*)) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc line 95
0x40153d92: operator new(unsigned int) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/build/build-cc-gcc-final/xtensa-esp32-elf/no-rtti/libstdc++-v3/include/bits/exception.h line 63
0x40155275: std::__cxx11::basic_string , std::allocator >::_M_create(unsigned int&, unsigned int) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/build/build-cc-gcc-final/xtensa-esp32-elf/no-rtti/libstdc++-v3/include/ext/new_allocator.h line 99
0x4015551d: std::__cxx11::basic_string , std::allocator >::reserve(unsigned int) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/build/build-cc-gcc-final/xtensa-esp32-elf/no-rtti/libstdc++-v3/include/bits/basic_string.h line 189
0x400dddef: std::operator+ , std::allocator >(char const*, std::__cxx11::basic_string , std::allocator > const&) at c:\users\yanna\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits/char_traits.h line 287
0x400de337: Web3::EthGetTransactionCount(std::__cxx11::basic_string , std::allocator > const*) (C:\Program Files at x86)\Arduino\libraries\web3-arduino\src\Web3.cpp line 137
0x400d293a: eth_send_example() at C:\Users\yanna\Documents\Arduino\basic_web3\eth_send/eth_send.ino line 53
0x400d2ada: setup() at C:\Users\yanna\Documents\Arduino\basic_web3\eth_send/eth_send.ino line 43
0x400e0366: loopTask(void*) at C:\Users\yanna\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32\main.cpp line 42
This is my codes
#include <WiFi.h>
#include <Web3.h>
#include <Contract.h>
#define USE_SERIAL Serial
const char* ssid = "V1A7C";
const char* password = /*<password>*/;
#define MY_ADDRESS "0x1b9aE0Be6d87e79b9Bd5A6FcDc67d92F76F6e0F6"
#define CONTRACT_ADDRESS "0xDA832c3825A37d693d17D9360d5289B8B2b580f0"
#define INFURA_HOST "eth-rinkeby.alchemyapi.io"
#define INFURA_PATH "/v2/1yNgxbZKvL4JzOIjnNUywYue0ruh_Fjt"
const char PRIVATE_KEY[] = {/*<32 bytes of private key>*/};
Web3 web3((string*)INFURA_HOST, (string*)INFURA_PATH);
void eth_send_example();
void setup() {
USE_SERIAL.begin(115200);
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFi.begin(ssid, password);
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
// wait 1 second for re-trying
delay(1000);
}
USE_SERIAL.println("Connected");
eth_send_example();
}
void loop() {
// put your main code here, to run repeatedly:
}
void eth_send_example() {
Contract contract(&web3,(string*) CONTRACT_ADDRESS);
contract.SetPrivateKey((uint8_t*)PRIVATE_KEY);
uint32_t nonceVal = (uint32_t)web3.EthGetTransactionCount((string *)MY_ADDRESS);
uint32_t gasPriceVal = 141006540;
uint32_t gasLimitVal = 3000000;
uint8_t toStr[] = CONTRACT_ADDRESS;
uint8_t valueStr[] = "0x00";
uint8_t dataStr[100];
memset(dataStr, 0, 100);
string func = "mint(uint256)";
string p = contract.SetupContractData(&func, 123);
string result = contract.SendTransaction(nonceVal, gasPriceVal, gasLimitVal, (string*) &toStr,(string*) &valueStr,(string*) &p);
Serial.println(result);
}
You are casting C char pointers to std::string pointers like this.
#define MY_ADDRESS "..."
...
uint32_t nonceVal = (uint32_t)web3.EthGetTransactionCount((string *)MY_ADDRESS);
Don't do that. If you need a pointer to a string
, you should create an instance of the string
like this.
string address = MY_ADDRESS;
uint32_t nonceVal = (uint32_t)web3.EthGetTransactionCount(&address);
As a side note, I don't recommend to use the web3-arduino.(I am very certain that the author of that library is a novice on C++.)