swapper-org / NodeChain

Nodechain is a service that allows you to create nodes on a blockchain and connect to them natively through APIs. The goal is to allow the user to build their own nodes natively without having to rely on external services.
MIT License
7 stars 5 forks source link

eth_call method #101

Closed 0xp3gasus closed 2 years ago

0xp3gasus commented 2 years ago

Description

Fixes #100

Dependencies (if any)

None

Type of change

How Has This Been Tested?

A sample Smart contract has been deployed to Regtest network in ETH, then, new RPC method has been executed to call the getMessage function of the contract

Contract code

//SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.11;

contract SampleContract {
    bytes32 message;
    constructor(bytes32 myMessage){
        message = myMessage;
    }
    function getMessage() public view returns(bytes32){
        return message;
    }
}

Deployment code

var argHex = web3.utils.asciiToHex("Hello world");
var deployContractTx = SampleContract.deploy(
    {
        data: bytecode,
        arguments: [argHex]
    }
);

New RPC method execution

curl --location --request POST 'http://localhost:80/eth/regtest/rpc' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": 1616785946469,
    "method": "call",
    "params": {
        "transaction": {
            "to": "0x976F996Aea68Fd7C07CADb632ab60eD95753f5C4",
            "data": "0xce6d41de"
        },
        "blockNumber": "latest"
    },
    "jsonrpc": "2.0"
}'
{
    "id": 1616785946469,
    "jsonrpc": "2.0",
    "result": {
        "data": "0x48656c6c6f20776f726c64000000000000000000000000000000000000000000"
    }
}

Data response decoded: Hello world

Test Configuration:

Related PR or Docs PR

Docs PR related # None Other PR related # None

Good practices to consider