mhw0 / libethc

Open-source Ethereum C library
https://mhw0.github.io/libethc/
MIT License
46 stars 8 forks source link

RPC calls #13

Closed DerXanRam closed 10 months ago

DerXanRam commented 11 months ago

we can use this header like this in main.cpp

#include <iostream>
#include <unordered_map>
#include <nlohmann/json.hpp>

using namespace std;
int main()
{
    unordered_map<string, string> parameters;
    string url="https://eth-mainnet.blastapi.io/";  //the api access provider
    string path= "b871b6ef-cdc2-4c11-b791-9fnchfhfv77v78d";  //fill your own api key from the provider
    string params = R"("0xa9d0a7dC416f586491f2fb596731598F937617b5", "latest")"; //raw string
    string method = "eth_getBalance";  //the method
    json res;
    parameters.insert({{"id", "0"},
                {"params", params},
                {"method", "eth_getBalance"},
                {"jsonrpc", "2.0"}

    });
    res = RPC("POST", parameters,url,path);
    cout<<res.dump()<<endl;   //to see all the response from the api
    cout << "response " << res["result"] << endl;  //to get specific key vale(for more detail about json, see nlohmann github
}

This header is tested againist infura.io and blastapi.io.

This headers and libraries are must be included to compile

"-I./curl/include",
"-L./curl/lib",
 "-L /usr/local/lib",
"-lethc",
 "-lcurl",
"-lcrypto" 
mhw0 commented 11 months ago

Thank you for the PR! We defenitely need some built-in functions to interact with RPCs. But, since it's a C library, we should keep the code in C language. And, also, all the new functions must follow some rules (like each public function should start with the eth_ prefix and header files should go in the include/ethc folder etc.) to keep the API of the library stable.

Using external libraries for serializing/deserializing JSON data? I don't know. I think it's better to make our own to keep the library as dependency free as possible. For making http calls, it's totally fine to use CURL.

So, I can't merge this PR right now, but it stays open. Again, thanks for the PR!

DerXanRam commented 11 months ago

Thank you for the PR! We defenitely need some built-in functions to interact with RPCs. But, since it's a C library, we should keep the code in C language. And, also, all the new functions must follow some rules (like each public function should start with the eth_ prefix and header files should go in the include/ethc folder etc.) to keep the API of the library stable.

Using external libraries for serializing/deserializing JSON data? I don't know. I think it's better to make our own to keep the library as dependency free as possible. For making http calls, it's totally fine to use CURL.

So, I can't merge this PR right now, but it stays open. Again, thanks for the PR!

Hello bro...thanks for revising the PR. As u saied, the header i write have some dependencies on external json parser and curl. Also it is c++. It is very stable and it may use as a reference for the future if u want to include this feature. I am not very good at C but i will try to make a C version of this. Tnx bro :pray:

mhw0 commented 11 months ago

Of course, I'll take inspirations from this PR. It's a great feature to have.

DerXanRam commented 11 months ago

Of course, I'll take inspirations from this PR. It's a great feature to have.

ok bro :+1: .....i will code the header to fit the standard u specified. And also i was using nlohmann to parse previously. So to switch to this lib and make everything fit, it needs some time.... i will PR as soon as i finished it.

Have a nice day bro :+1:

mhw0 commented 11 months ago

Any progress on this?

DerXanRam commented 11 months ago

Any progress on this?

yes. But little straggle to fit in to the architecture u provided. The rest is progressing in good way :+1: .

DerXanRam commented 10 months ago

Hey bro. How are u. I'm not online this two day due to some personal problems. I think i will back tomorrow. Soryy for late🙏

mhw0 commented 10 months ago

Hey @DerXanRam . No worries, you don't have to.

DerXanRam commented 10 months ago

Hey @DerXanRam . No worries, you don't have to.

Hello mate. I'm back after 6 Hard days. How was everything?

mhw0 commented 10 months ago

Hey @DerXanRam If you don't have free time to work on this, I'll merge the dev branch.

DerXanRam commented 10 months ago

Hey @DerXanRam If you don't have free time to work on this, I'll merge the dev branch.

Hello mate. do u mean integrating the mpint integration now to main branch?

mhw0 commented 10 months ago

@DerXanRam Yes, there are some other changes as well in that branch. I'll merge the dev branch and bump the version. This feature will be in the next versions (1.2.0?)

DerXanRam commented 10 months ago

@DerXanRam Yes, there are some other changes as well in that branch. I'll merge the dev branch and bump the version. This feature will be in the next versions (1.2.0?)

ok mate..... merg it and i will PR when i finished it :+1:

mhw0 commented 10 months ago

Created feat-rpc branch for this feature.

mhw0 commented 10 months ago

Closing the PR: https://github.com/mhw0/libethc/pull/28#issuecomment-1721092608