AlphaWallet / Web3E

Web3E Ethereum for Embedded devices running Arduino framework
MIT License
142 stars 45 forks source link

Runtime error on ESP32 using Contract.h #9

Open kenokenobingo opened 3 years ago

kenokenobingo commented 3 years ago

I’m using Web3E with an ESP32. Standalone Web3.h works fine, but Contract.h causes problems, though. This is what I’m trying to do:

queryERC20Balance(ERC20CONTRACT, MY_ADDRESS);

Whereas void queryERC20Balance(const char* Address, const char* ERC20ContractAddress) is taken from the repo examples:

void queryERC20Balance(const char* contractAddress, const char *userAddress)
{
    String address = userAddress;

    string param = contract.SetupContractData("balanceOf(address)", &address);
    string result = contract.ViewCall(&param);

    param = contract.SetupContractData("decimals()", &address);
    result = contract.ViewCall(&param);

    int decimals = web3.getInt(&result);

    uint256_t baseBalance = web3.getUint256(&result);
    string balanceStr = Util::ConvertWeiToEthString(&baseBalance, decimals); //use decimals to calculate value, not all ERC20 use 18 decimals

    Serial.println(balanceStr.c_str());
}

This is the decoded backtrace:

Backtrace: 0x40085058:0x3ffb1ba0 0x400852d5:0x3ffb1bc0 0x400f6777:0x3ffb1be0 0x400f67be:0x3ffb1c00 0x400f5ddf:0x3ffb1c20 0x400f61de:0x3ffb1c40 0x400fc00d:0x3ffb1c60 0x400d239f:0x3ffb1c80 0x400d254b:0x3ffb1cb0 0x400d2b65:0x3ffb1d40 0x400d1a47:0x3ffb1eb0 0x400d1c92:0x3ffb1f80 0x400df282:0x3ffb1fb0 0x400862d6:0x3ffb1fd0
  #0  0x40085058:0x3ffb1ba0 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #1  0x400852d5:0x3ffb1bc0 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #2  0x400f6777:0x3ffb1be0 in __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:112
  #3  0x400f67be:0x3ffb1c00 in std::terminate() at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:112
  #4  0x400f5ddf:0x3ffb1c20 in __cxa_throw at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_throw.cc:87
  #5  0x400f61de:0x3ffb1c40 in operator new(unsigned int) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/new_op.cc:54
  #6  0x400fc00d:0x3ffb1c60 in __gnu_cxx::new_allocator<char>::allocate(unsigned int, void const*) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/build/build-cc-gcc-final/xtensa-esp32-elf/libstdc++-v3/include/bits/basic_string.h:2200
      (inlined by) std::allocator_traits<std::allocator<char> >::allocate(std::allocator<char>&, unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/build/build-cc-gcc-final/xtensa-esp32-elf/libstdc++-v3/include/bits/alloc_traits.h:360
      (inlined by) std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/build/build-cc-gcc-final/xtensa-esp32-elf/libstdc++-v3/include/bits/basic_string.tcc:157
  #7  0x400d239f:0x3ffb1c80 in void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) at /Users/keno/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/basic_string.tcc:223
  #8  0x400d254b:0x3ffb1cb0 in void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct_aux<char*>(char*, char*, std::__false_type) at /Users/keno/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/basic_string.h:195
      (inlined by) void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*) at /Users/keno/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/basic_string.h:214
      (inlined by) std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) at /Users/keno/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/bits/basic_string.h:401
      (inlined by) Contract::GenerateBytesForAddress(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*) at lib/Web3E/src/Contract.cpp:216
  #9  0x400d2b65:0x3ffb1d40 in Contract::SetupContractData[abi:cxx11](char const*, ...) at lib/Web3E/src/Contract.cpp:99 (discriminator 7)
  #10 0x400d1a47:0x3ffb1eb0 in queryERC20Balance(char const*, char const*) at src/main.cpp:101
  #11 0x400d1c92:0x3ffb1f80 in setup() at src/main.cpp:88
  #12 0x400df282:0x3ffb1fb0 in loopTask(void*) at /Users/keno/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:32
  #13 0x400862d6:0x3ffb1fd0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

Can someone help me with that, please? It seems there’s a probkem with Contract::GenerateBytesForAddress(), right?

JamesSmartCell commented 2 years ago

I'll need to check the examples - they all work locally on my ESP32 Wrover setup.

Which ESP32 are you using? Also, it need the Arduino Framework. I haven't yet ported it to ESPIDF.

JamesSmartCell commented 1 year ago

Hi @kenokenobingo I think this should be fixed now, does it work?