Hi everyone
Im trying to send the transaction on my deployed smart contract (Sepolia) via ESP32 Web3
The contract is most basic
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
contract SmartContractDeployment {
uint256 number;
event Log(string message);
function store(uint256 num) public {
emit Log("new number stored");
number = num;
}
function retrieve() public view returns (uint256){
return number;
}
}
but I encountered some issues with coding
MY_ADDRESS is the address that pays for the transaction
SETUPCONTRACT is the address of the contract deployed on the network
void setup() {
Serial.begin(115200);
web3 = new Web3(SEPOLIA_ID);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
sendTransactionToSmartContract(MY_ADDRESS, SETUPCONTRACT);
}
void sendTransactionToSmartContract(const char *toAddr, const char *contractAddr)
{
string contractAddrStr = contractAddr; // contract Address
Contract contract(web3, contractAddr); // connect to contract in Web3
contract.SetPrivateKey(PRIVATE_KEY); // set private key of your wallet
string address = MY_ADDRESS; // write address in string
// //Get contract name (This isn't needed to push the transaction)
// string param = contract.SetupContractData("name()", &toAddr); // set up contract data to return the name of the contract
// string result = contract.ViewCall(¶m); //
// string interpreted = Util::InterpretStringResult(web3->getString(&result).c_str());
// Serial.println(interpreted.c_str());
// //Get Contract decimals
// param = contract.SetupContractData("decimals()", &toAddr);
// result = contract.ViewCall(¶m);
// int decimals = web3->getInt(&result);
// Serial.println(decimals);
// //amount of erc20 token to send, note we use decimal value obtained earlier
// uint256_t weiValue = Util::ConvertToWei(tokens, decimals);
//get nonce
Serial.print("Get Nonce: ");
string toAddress = toAddr;
uint32_t nonceVal = (uint32_t)web3->EthGetTransactionCount(&address); // nonce Val
unsigned long long gasPriceVal = 2200000000LL;
uint32_t gasLimitVal = 4300000;
uint256_t callValue = 0;
Serial.println(nonceVal);
Serial.println("Send TX");
//Setup contract function call
string p = contract.SetupContractData("store(uint256)", 123);
//push transaction to ethereum
string result = contract.SendTransaction(nonceVal, gasPriceVal, gasLimitVal, &contractAddrStr, &callValue, &p);
Serial.println(result.c_str());
string transactionHash = web3->getResult(&result);
Serial.println("TX on Etherscan:");
Serial.print(ETHERSCAN_TX);
Serial.println(transactionHash.c_str()); //you can go straight to etherscan and see the pending transaction
}
Loop and wifi connections are fine
Keep receiving this error
WiFi connected.
IP address:
172.20.10.4
Get Nonce: 332
Send TX
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400db0a7 PS : 0x00060530 A0 : 0x800db127 A1 : 0x3ffcc5f0
A2 : 0x0000007b A3 : 0x3ffcc664 A4 : 0x0000007b A5 : 0x3ffd75ac
A6 : 0x3ffcc7d0 A7 : 0x3ffcc960 A8 : 0x8009248c A9 : 0x3ffcc5e0
A10 : 0x3ffd8370 A11 : 0x3ffd8370 A12 : 0x3ffd7594 A13 : 0x3ffcc7a2
A14 : 0x00000036 A15 : 0x00000035 SAR : 0x00000014 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000082 LBEG : 0x40089975 LEND : 0x40089985 LCOUNT : 0xfffffff7
Backtrace: 0x400db0a4:0x3ffcc5f0 0x400db124:0x3ffcc620 0x400db35a:0x3ffcc640 0x400d6af7:0x3ffcc660 0x400d71c1:0x3ffcc690 0x400d2f51:0x3ffcc7d0 0x400d3191:0x3ffcc980 0x400ddbe6:0x3ffcc9c0
Can somebody help please