0

IMPORTANT

My final goal is receive data via api on a php server and use Infura to call my contract to save the data

Test Situation

having this test contract on rinkeby

contract test008 {

    mapping (uint256 => string ) private storedData;

    function set(uint _index, string memory _data_to_store) public {
        storedData[_index] = _data_to_store;
    }

    function get(uint _index) public view returns (string memory) {
        return storedData[_index];
    }
}

What's the right syntax to call

set(100, 'hello world') 

??

Using curl, How can I pass the data using the -d option?

curl https://rinkeby.infura.io/v3/<project_id>\
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_call","params": [ { "to":"hex_address_of_my_contact", "data" : " ??????  " }, "latest" ]}

I must specify eth address of contract in the to, right?

I must specify name of function, but how ?

And then I must pass parameters, but ... how ?

From the doc of eth_call function

data: [optional] Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI

Is this data param the place where specify function name and parameters for the call? If yes.... how ?!

Core question

if all is really about the data param .... ....

Can I generate data hash having function name and parameters? How? Is there any doc about how to do this encoding ? Better: do you know encoding php library?

  • Write a script using Web3.js, and then run this script via NodeJS. – goodvibration Jan 10 at 17:21
  • I need a server to server solution, this is way I am using Infura and JsonRPC. I expained better, I hope, my problem, goal and the core of my question: where pass function name and parameters and how to encode these infos if really I must use the encoded data param – realtebo Jan 10 at 17:35
  • 1
    Take a look at github.com/sc0Vu/web3.php it provides the ability to make a call to a contract. – Ismael Jan 11 at 14:27
1

web3.js can be also used in a server side environment, depending of your language implementation, and it is the best way to do it.

Doing it manually is possible, but you will need to encode all the parameters and the signature, and sign the transaction to.

Here is an article with some detail on ethereum transaction format: Inside an Ethereum transaction It describes all the necessary steps to achieve such thing.

| improve this answer | |
  • Thanks for pointing me to an article where data hasing is explained very well. Don't you know a PHP library for this? – realtebo Jan 21 at 8:17
1

You are trying to update the state of your contract and for this you have to execute blockchain transaction, but eth_call is not for firing transactions read more here. What can work for your case is using eth_sendRawTransaction read more here. In params you have to place the transaction data which have to be signed by the private key of the transaction creator.

| improve this answer | |
  • Thanks for pointing me to the right API – realtebo Jan 21 at 8:15

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.