1

Indeed, i installed ganache where i deployed a smart contract. I wanted to write a c program that would allow me to call the functions of my smart contract and read the messages. This program would then have to be executed in connected objects. I did some research, but I can't figure out how to do it, but i guess i will use the JSON-RPC protocol, in this case how to call json-rpc from my c program to access my smart contract

6
  • The basic idea is to open a socket to the RPC port and write JSON to the socket and wait for the result. If you like fancy things use a library like libuv to manage networking and jansson for the JSON formatting.
    – Ismael
    Feb 22 at 5:51
  • Thanks for your reaction...I'm new to blockchain programming, I'd just like a few things that work for now ... I was thinking of integrating web3.js into the C program but no way. So I thought about using Json-rpc to communicate with the smart contract... But I'm still having problems ... ok I'll check with jansson and if you also have any other suggestions or links to offer me, it could help me.
    – assya
    Feb 24 at 16:02
  • Do you need a code for data exchange via sockets or a description of the json-rpc functions and a data packaging scheme for exchanging with smart contracts?
    – Mad Jackal
    Feb 24 at 17:29
  • I won't recommend using C if you are learning about ethereum. Use some high level language like python or javascript that have a good libraries web3.py and web3.js until you are more accustomed to it.
    – Ismael
    Feb 24 at 19:07
  • indeed I code iot objects that must access the ethereum blockchain... and for the embedded systems the C, C++ languages are the most used... and I am used to use the C language for this fact... so I have my program in C I coded and tested my smart contract on remix then I deployed it on ganache to do local tests. but I can't find a way to access the smart contract from my c
    – assya
    Feb 25 at 12:27
1

Ganache is as server node to ethereum chain and you can using standart ethereum rpc api (attention, look port , default,7545 , but bettet to check, see here more details about configuration ganache https://www.trufflesuite.com/docs/ganache/reference/workspace-default-configuration)

For calling method to only getting data from smart you should using https://eth.wiki/json-rpc/API#eth_call.

For call function and transfer data to smart contact you should to call

  1. https://eth.wiki/json-rpc/API#eth_estimategas
  2. https://eth.wiki/json-rpc/API#eth_sendtransaction

Be carefully then formed data to eth_sendTransaction.

1
  • Thank you for your reaction, I will look into it... However, do you know a json-rpc api for the C language? Indeed, I program in C and I need to access the smart contract using Json-rpc.
    – assya
    Feb 24 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.