Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error on ESP32 using Contract.h #9

Open
kenokenobingo opened this issue Jun 16, 2021 · 2 comments
Open

Runtime error on ESP32 using Contract.h #9

kenokenobingo opened this issue Jun 16, 2021 · 2 comments

Comments

@kenokenobingo
Copy link

kenokenobingo commented Jun 16, 2021

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
Copy link
Member

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants