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

Updated to compile and work with ESP32 1.0.6 #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ src/examples/*
readme_for_me.md
tools/
lib/
.\#*
\#*\#
*~

.pioenvs
.piolibdeps
Expand Down
2 changes: 0 additions & 2 deletions .idea/clion.iml

This file was deleted.

29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/modules.xml

This file was deleted.

2 changes: 0 additions & 2 deletions .idea/platformio.iml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/serialmonitor_settings.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

30 changes: 0 additions & 30 deletions .idea/watcherTasks.xml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## unmaintained
## updated: compile and works as of ESP32 1.0.6 tested on a Dev Module


Sorry but I cannot take time to maintain the library now...

## web3-arduino

Expand Down
19 changes: 19 additions & 0 deletions examples/Contract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 ;
contract RyanCoin {
mapping (address => uint) public balances;
uint constant public PRICE = 2000000000000000; // 2 mETH as PRICE

constructor() public {
}

function buyCoin() public payable{ // pay ETH to create coin
require(msg.value > 0);
balances[msg.sender] += (msg.value / PRICE);
}

function getBalance(
) public view returns(uint){
return balances[msg.sender];
}
}
83 changes: 32 additions & 51 deletions examples/basic_eth/basic_eth.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
#include <Arduino.h>
#include <WiFi.h>
#include <Web3.h>
#include <esp_system.h>
#include <esp_log.h>


#define USE_SERIAL Serial


#define ENV_SSID "<YOUR_SSID>"
#define ENV_WIFI_KEY "<YOUR_PASSWORD>"
#define INFURA_HOST "rinkeby.infura.io"
#define INFURA_PATH "/<YOUR_INFURA_ID>"
#define ADDRESS "0x<YOUR_ETH_ADDRESS>"

Web3 web3(INFURA_HOST, INFURA_PATH);
Web3 web3(new std::string(INFURA_HOST), new std::string( INFURA_PATH));

void eth_example();
void net_example();

String getMacAddress() {
uint8_t baseMac[6];
// Get MAC address for WiFi station
esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
char baseMacChr[18] = {0};
sprintf(baseMacChr, "%02X:%02X:%02X:%02X:%02X:%02X", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]);
return String(baseMacChr);
}

void setup() {
USE_SERIAL.begin(115200);
Expand All @@ -24,6 +37,9 @@ void setup() {

WiFi.begin(ENV_SSID, ENV_WIFI_KEY);

String mac = getMacAddress();
USE_SERIAL.println(mac);

// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
Expand All @@ -33,62 +49,27 @@ void setup() {

USE_SERIAL.println("Connected");

eth_example();
net_example();
}

void loop() {
// put your main code here, to run repeatedly:
// put your main code here, to run repeatedly:
}

void eth_example() {
char tmp[32];
void net_example() {
int version = web3.NetVersion();
USE_SERIAL.println("net_version");
USE_SERIAL.println(version); // this is 4

double version = web3.EthProtocolVersion();
USE_SERIAL.println("eth_protocolVersion");
USE_SERIAL.println(version);

bool listening = web3.EthSyncing();
USE_SERIAL.println("eth_syncing");
bool listening = web3.NetListening();
USE_SERIAL.println("net_listening");
if (listening) {
USE_SERIAL.println("syncing");
} else{
USE_SERIAL.println("not syncing");
}

bool mining = web3.EthMining();
USE_SERIAL.println("eth_mining");
if (mining) {
USE_SERIAL.println("mining");
USE_SERIAL.println("listening");
} else{
USE_SERIAL.println("not mining");
USE_SERIAL.println("not listening");
}

double hashrate = web3.EthHashrate();
USE_SERIAL.println("eth_hashrate");
USE_SERIAL.println(hashrate);

long long int gasPrice = web3.EthGasPrice();
USE_SERIAL.println("eth_gasPrice");
memset(tmp, 0, 32);
sprintf(tmp, "%lld", gasPrice);
USE_SERIAL.println(tmp);

int blockNumber = web3.EthBlockNumber();
USE_SERIAL.println("eth_blockNumber");
memset(tmp, 0, 32);
sprintf(tmp, "%d", blockNumber);
USE_SERIAL.println(tmp);

string address = "0xd7049ea6f47ef848C0Ad570dbA618A9f6e4Eb25C";
long long int balance = web3.EthGetBalance(&address);
USE_SERIAL.println("eth_getBalance");
memset(tmp, 0, 32);
sprintf(tmp, "%lld", balance);
USE_SERIAL.println(tmp);

int txcount = web3.EthGetTransactionCount(&address);
USE_SERIAL.println("eth_getTransactionCount");
memset(tmp, 0, 32);
sprintf(tmp, "%d", txcount);
USE_SERIAL.println(tmp);
int peerCount = web3.NetPeerCount();
USE_SERIAL.println("net_peerCount");
USE_SERIAL.println(peerCount);
}
20 changes: 18 additions & 2 deletions examples/basic_net/basic_net.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <Arduino.h>
#include <WiFi.h>
#include <Web3.h>
#include <esp_system.h>
#include <esp_log.h>


#define USE_SERIAL Serial

Expand All @@ -8,10 +12,20 @@
#define INFURA_HOST "rinkeby.infura.io"
#define INFURA_PATH "/<YOUR_INFURA_ID>"

Web3 web3(INFURA_HOST, INFURA_PATH);
Web3 web3(new std::string(INFURA_HOST), new std::string( INFURA_PATH));


void net_example();

String getMacAddress() {
uint8_t baseMac[6];
// Get MAC address for WiFi station
esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
char baseMacChr[18] = {0};
sprintf(baseMacChr, "%02X:%02X:%02X:%02X:%02X:%02X", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]);
return String(baseMacChr);
}

void setup() {
USE_SERIAL.begin(115200);

Expand All @@ -23,6 +37,9 @@ void setup() {

WiFi.begin(ENV_SSID, ENV_WIFI_KEY);

String mac = getMacAddress();
USE_SERIAL.println(mac);

// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
Expand Down Expand Up @@ -56,4 +73,3 @@ void net_example() {
USE_SERIAL.println("net_peerCount");
USE_SERIAL.println(peerCount);
}

25 changes: 21 additions & 4 deletions examples/basic_web3/basic_web3.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#include <Arduino.h>
#include <WiFi.h>
#include <Web3.h>
#include <esp_system.h>
#include <esp_log.h>


#define USE_SERIAL Serial


#define ENV_SSID "<YOUR_SSID>"
#define ENV_WIFI_KEY "<YOUR_PASSWORD>"
#define INFURA_HOST "rinkeby.infura.io"
#define INFURA_PATH "/<YOUR_INFURA_ID>"

Web3 web3(INFURA_HOST, INFURA_PATH);
Web3 web3(new std::string(INFURA_HOST), new std::string( INFURA_PATH));

void web3_example();

String getMacAddress() {
uint8_t baseMac[6];
// Get MAC address for WiFi station
esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
char baseMacChr[18] = {0};
sprintf(baseMacChr, "%02X:%02X:%02X:%02X:%02X:%02X", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]);
return String(baseMacChr);
}

void setup() {
USE_SERIAL.begin(115200);

Expand All @@ -23,6 +37,9 @@ void setup() {

WiFi.begin(ENV_SSID, ENV_WIFI_KEY);

String mac = getMacAddress();
USE_SERIAL.println(mac);

// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
Expand All @@ -41,11 +58,11 @@ void loop() {

void web3_example() {
string result = web3.Web3ClientVersion();
USE_SERIAL.println("web3_ClientVersion");
USE_SERIAL.println("web3_ClientVersion"); //returns current client version
USE_SERIAL.println(result.c_str());

string src = "0x68656c6c6f20776f726c64";
string src = "0x68656c6c6f20776f726c64"; //data to hash
result = web3.Web3Sha3(&src);
USE_SERIAL.println("web3_sha3");
USE_SERIAL.println("web3_sha3"); // this is the Keccak-256 hash ( not the NIST SHA3-256)
USE_SERIAL.println(result.c_str()); // 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad
}
Loading