How to correctly send RPC call using Golang to get smart-contract owner?











up vote
1
down vote

favorite












Update



Since I'm not able to achieve this using the approach in this question, I created my own library to do the same thing (link). It doesn't rely on go-ethereum package but use the normal net/http package to do JSON RPC request.



I still love to know what I did wrong in my approach below.





Definitions:





  • owner = public variable in contract with address type


  • contract = smart-contract that has owner


This is the curl request to get the owner of a contract. I managed to get the owner. (JSON RPC docs)



curl localhost:8545 -X POST 
--header 'Content-type: application/json'
--data '{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to": "0x_MY_CONTRACT_ADDRESS", "data": "0x8da5cb5b"}, "latest"], "id":1}'

{"jsonrpc":"2.0","id":1,"result":"0x000000000000000000000000_OWNER"}


But when I try to replicate it in Golang (code below), I got json: cannot unmarshal string into Go value of type main.response error. (go-ethereum code that I use)



package main

import (
"fmt"
"log"
"os"

"github.com/ethereum/go-ethereum/rpc"
)

func main() {
client, err := rpc.DialHTTP(os.Getenv("RPC_SERVER"))
if err != nil {
log.Fatal(err)
}
defer client.Close()

type request struct {
To string `json:"to"`
Data string `json:"data"`
}

type response struct {
Result string
}

req := request{"0x_MY_CONTRACT_ADDRESS", "0x8da5cb5b"}
var resp response
if err := client.Call(&resp, "eth_call", req, "latest"); err != nil {
log.Fatal(err)
}

fmt.Printf("%vn", resp)
}


What did I miss here?



Expected result:



Address in string format. E.g. 0x3ab17372b25154400738C04B04f755321bB5a94b



P/S — I'm aware of abigen and I know it's better and easier to do this using abigen. But I'm trying to solve this specific issue without using abigen method.










share|improve this question




























    up vote
    1
    down vote

    favorite












    Update



    Since I'm not able to achieve this using the approach in this question, I created my own library to do the same thing (link). It doesn't rely on go-ethereum package but use the normal net/http package to do JSON RPC request.



    I still love to know what I did wrong in my approach below.





    Definitions:





    • owner = public variable in contract with address type


    • contract = smart-contract that has owner


    This is the curl request to get the owner of a contract. I managed to get the owner. (JSON RPC docs)



    curl localhost:8545 -X POST 
    --header 'Content-type: application/json'
    --data '{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to": "0x_MY_CONTRACT_ADDRESS", "data": "0x8da5cb5b"}, "latest"], "id":1}'

    {"jsonrpc":"2.0","id":1,"result":"0x000000000000000000000000_OWNER"}


    But when I try to replicate it in Golang (code below), I got json: cannot unmarshal string into Go value of type main.response error. (go-ethereum code that I use)



    package main

    import (
    "fmt"
    "log"
    "os"

    "github.com/ethereum/go-ethereum/rpc"
    )

    func main() {
    client, err := rpc.DialHTTP(os.Getenv("RPC_SERVER"))
    if err != nil {
    log.Fatal(err)
    }
    defer client.Close()

    type request struct {
    To string `json:"to"`
    Data string `json:"data"`
    }

    type response struct {
    Result string
    }

    req := request{"0x_MY_CONTRACT_ADDRESS", "0x8da5cb5b"}
    var resp response
    if err := client.Call(&resp, "eth_call", req, "latest"); err != nil {
    log.Fatal(err)
    }

    fmt.Printf("%vn", resp)
    }


    What did I miss here?



    Expected result:



    Address in string format. E.g. 0x3ab17372b25154400738C04B04f755321bB5a94b



    P/S — I'm aware of abigen and I know it's better and easier to do this using abigen. But I'm trying to solve this specific issue without using abigen method.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Update



      Since I'm not able to achieve this using the approach in this question, I created my own library to do the same thing (link). It doesn't rely on go-ethereum package but use the normal net/http package to do JSON RPC request.



      I still love to know what I did wrong in my approach below.





      Definitions:





      • owner = public variable in contract with address type


      • contract = smart-contract that has owner


      This is the curl request to get the owner of a contract. I managed to get the owner. (JSON RPC docs)



      curl localhost:8545 -X POST 
      --header 'Content-type: application/json'
      --data '{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to": "0x_MY_CONTRACT_ADDRESS", "data": "0x8da5cb5b"}, "latest"], "id":1}'

      {"jsonrpc":"2.0","id":1,"result":"0x000000000000000000000000_OWNER"}


      But when I try to replicate it in Golang (code below), I got json: cannot unmarshal string into Go value of type main.response error. (go-ethereum code that I use)



      package main

      import (
      "fmt"
      "log"
      "os"

      "github.com/ethereum/go-ethereum/rpc"
      )

      func main() {
      client, err := rpc.DialHTTP(os.Getenv("RPC_SERVER"))
      if err != nil {
      log.Fatal(err)
      }
      defer client.Close()

      type request struct {
      To string `json:"to"`
      Data string `json:"data"`
      }

      type response struct {
      Result string
      }

      req := request{"0x_MY_CONTRACT_ADDRESS", "0x8da5cb5b"}
      var resp response
      if err := client.Call(&resp, "eth_call", req, "latest"); err != nil {
      log.Fatal(err)
      }

      fmt.Printf("%vn", resp)
      }


      What did I miss here?



      Expected result:



      Address in string format. E.g. 0x3ab17372b25154400738C04B04f755321bB5a94b



      P/S — I'm aware of abigen and I know it's better and easier to do this using abigen. But I'm trying to solve this specific issue without using abigen method.










      share|improve this question















      Update



      Since I'm not able to achieve this using the approach in this question, I created my own library to do the same thing (link). It doesn't rely on go-ethereum package but use the normal net/http package to do JSON RPC request.



      I still love to know what I did wrong in my approach below.





      Definitions:





      • owner = public variable in contract with address type


      • contract = smart-contract that has owner


      This is the curl request to get the owner of a contract. I managed to get the owner. (JSON RPC docs)



      curl localhost:8545 -X POST 
      --header 'Content-type: application/json'
      --data '{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to": "0x_MY_CONTRACT_ADDRESS", "data": "0x8da5cb5b"}, "latest"], "id":1}'

      {"jsonrpc":"2.0","id":1,"result":"0x000000000000000000000000_OWNER"}


      But when I try to replicate it in Golang (code below), I got json: cannot unmarshal string into Go value of type main.response error. (go-ethereum code that I use)



      package main

      import (
      "fmt"
      "log"
      "os"

      "github.com/ethereum/go-ethereum/rpc"
      )

      func main() {
      client, err := rpc.DialHTTP(os.Getenv("RPC_SERVER"))
      if err != nil {
      log.Fatal(err)
      }
      defer client.Close()

      type request struct {
      To string `json:"to"`
      Data string `json:"data"`
      }

      type response struct {
      Result string
      }

      req := request{"0x_MY_CONTRACT_ADDRESS", "0x8da5cb5b"}
      var resp response
      if err := client.Call(&resp, "eth_call", req, "latest"); err != nil {
      log.Fatal(err)
      }

      fmt.Printf("%vn", resp)
      }


      What did I miss here?



      Expected result:



      Address in string format. E.g. 0x3ab17372b25154400738C04B04f755321bB5a94b



      P/S — I'm aware of abigen and I know it's better and easier to do this using abigen. But I'm trying to solve this specific issue without using abigen method.







      go ethereum json-rpc smartcontracts go-ethereum






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 12:23

























      asked Nov 10 at 9:47









      Zulhilmi Zainudin

      3,36752752




      3,36752752
























          4 Answers
          4






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can solve the problem best using the go-ethereum/ethclient:



          package main

          import (
          "context"
          "log"

          "github.com/ethereum/go-ethereum"
          "github.com/ethereum/go-ethereum/common"
          "github.com/ethereum/go-ethereum/ethclient"
          )

          func main() {
          client, _ := ethclient.Dial("https://mainnet.infura.io")
          defer client.Close()

          contractAddr := common.HexToAddress("0xCc13Fc627EFfd6E35D2D2706Ea3C4D7396c610ea")
          callMsg := ethereum.CallMsg{
          To: &contractAddr,
          Data: common.FromHex("0x8da5cb5b"),
          }

          res, err := client.CallContract(context.Background(), callMsg, nil)
          if err != nil {
          log.Fatalf("Error calling contract: %v", err)
          }
          log.Printf("Owner: %s", common.BytesToAddress(res).Hex())
          }





          share|improve this answer























          • Thanks. This is the closest solution. Appreciate your help!
            – Zulhilmi Zainudin
            Nov 12 at 11:42


















          up vote
          0
          down vote













          Your response struct doesn't show the data that the json of the response has



          try this



          type response struct {
          Jsonrpc string `json:"jsonrpc"`
          ID int `json:"id"`
          Result string `json:"result"`
          }





          share|improve this answer





















          • Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
            – Zulhilmi Zainudin
            Nov 10 at 10:08










          • try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
            – Vorsprung
            Nov 10 at 10:10










          • I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
            – Zulhilmi Zainudin
            Nov 10 at 10:13










          • add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
            – Vorsprung
            Nov 10 at 10:19


















          up vote
          0
          down vote













          json: cannot unmarshal string into Go value of type main.response error. I got similar type error when i was unmarshaling a response. It was because the response was actually json string, i mean it had Quotation " as first character. So to be sure you also encountered the same problem, please printf("%v",resp.Result) before unmarshaling in here https://github.com/ethereum/go-ethereum/blob/1ff152f3a43e4adf030ac61eb5d8da345554fc5a/rpc/client.go#L278.






          share|improve this answer




























            up vote
            0
            down vote













            If you look at the client library code, you'll see that the JSON RPC response object is already disassembled and either an error is returned on failure, or the actual result parsed: https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go#L277



            The parser however already unwrapped the containing "result" field. Your type still wants to do an additional unwrap:



            type response struct {
            Result string
            }


            Drop the outer struct, simply pass a string pointer to the client.Call's first parameter.






            share|improve this answer





















            • Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
              – Zulhilmi Zainudin
              Nov 12 at 10:55













            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237759%2fhow-to-correctly-send-rpc-call-using-golang-to-get-smart-contract-owner%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            You can solve the problem best using the go-ethereum/ethclient:



            package main

            import (
            "context"
            "log"

            "github.com/ethereum/go-ethereum"
            "github.com/ethereum/go-ethereum/common"
            "github.com/ethereum/go-ethereum/ethclient"
            )

            func main() {
            client, _ := ethclient.Dial("https://mainnet.infura.io")
            defer client.Close()

            contractAddr := common.HexToAddress("0xCc13Fc627EFfd6E35D2D2706Ea3C4D7396c610ea")
            callMsg := ethereum.CallMsg{
            To: &contractAddr,
            Data: common.FromHex("0x8da5cb5b"),
            }

            res, err := client.CallContract(context.Background(), callMsg, nil)
            if err != nil {
            log.Fatalf("Error calling contract: %v", err)
            }
            log.Printf("Owner: %s", common.BytesToAddress(res).Hex())
            }





            share|improve this answer























            • Thanks. This is the closest solution. Appreciate your help!
              – Zulhilmi Zainudin
              Nov 12 at 11:42















            up vote
            1
            down vote



            accepted










            You can solve the problem best using the go-ethereum/ethclient:



            package main

            import (
            "context"
            "log"

            "github.com/ethereum/go-ethereum"
            "github.com/ethereum/go-ethereum/common"
            "github.com/ethereum/go-ethereum/ethclient"
            )

            func main() {
            client, _ := ethclient.Dial("https://mainnet.infura.io")
            defer client.Close()

            contractAddr := common.HexToAddress("0xCc13Fc627EFfd6E35D2D2706Ea3C4D7396c610ea")
            callMsg := ethereum.CallMsg{
            To: &contractAddr,
            Data: common.FromHex("0x8da5cb5b"),
            }

            res, err := client.CallContract(context.Background(), callMsg, nil)
            if err != nil {
            log.Fatalf("Error calling contract: %v", err)
            }
            log.Printf("Owner: %s", common.BytesToAddress(res).Hex())
            }





            share|improve this answer























            • Thanks. This is the closest solution. Appreciate your help!
              – Zulhilmi Zainudin
              Nov 12 at 11:42













            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            You can solve the problem best using the go-ethereum/ethclient:



            package main

            import (
            "context"
            "log"

            "github.com/ethereum/go-ethereum"
            "github.com/ethereum/go-ethereum/common"
            "github.com/ethereum/go-ethereum/ethclient"
            )

            func main() {
            client, _ := ethclient.Dial("https://mainnet.infura.io")
            defer client.Close()

            contractAddr := common.HexToAddress("0xCc13Fc627EFfd6E35D2D2706Ea3C4D7396c610ea")
            callMsg := ethereum.CallMsg{
            To: &contractAddr,
            Data: common.FromHex("0x8da5cb5b"),
            }

            res, err := client.CallContract(context.Background(), callMsg, nil)
            if err != nil {
            log.Fatalf("Error calling contract: %v", err)
            }
            log.Printf("Owner: %s", common.BytesToAddress(res).Hex())
            }





            share|improve this answer














            You can solve the problem best using the go-ethereum/ethclient:



            package main

            import (
            "context"
            "log"

            "github.com/ethereum/go-ethereum"
            "github.com/ethereum/go-ethereum/common"
            "github.com/ethereum/go-ethereum/ethclient"
            )

            func main() {
            client, _ := ethclient.Dial("https://mainnet.infura.io")
            defer client.Close()

            contractAddr := common.HexToAddress("0xCc13Fc627EFfd6E35D2D2706Ea3C4D7396c610ea")
            callMsg := ethereum.CallMsg{
            To: &contractAddr,
            Data: common.FromHex("0x8da5cb5b"),
            }

            res, err := client.CallContract(context.Background(), callMsg, nil)
            if err != nil {
            log.Fatalf("Error calling contract: %v", err)
            }
            log.Printf("Owner: %s", common.BytesToAddress(res).Hex())
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 at 11:37

























            answered Nov 12 at 11:06









            user10595796

            286




            286












            • Thanks. This is the closest solution. Appreciate your help!
              – Zulhilmi Zainudin
              Nov 12 at 11:42


















            • Thanks. This is the closest solution. Appreciate your help!
              – Zulhilmi Zainudin
              Nov 12 at 11:42
















            Thanks. This is the closest solution. Appreciate your help!
            – Zulhilmi Zainudin
            Nov 12 at 11:42




            Thanks. This is the closest solution. Appreciate your help!
            – Zulhilmi Zainudin
            Nov 12 at 11:42












            up vote
            0
            down vote













            Your response struct doesn't show the data that the json of the response has



            try this



            type response struct {
            Jsonrpc string `json:"jsonrpc"`
            ID int `json:"id"`
            Result string `json:"result"`
            }





            share|improve this answer





















            • Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
              – Zulhilmi Zainudin
              Nov 10 at 10:08










            • try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
              – Vorsprung
              Nov 10 at 10:10










            • I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
              – Zulhilmi Zainudin
              Nov 10 at 10:13










            • add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
              – Vorsprung
              Nov 10 at 10:19















            up vote
            0
            down vote













            Your response struct doesn't show the data that the json of the response has



            try this



            type response struct {
            Jsonrpc string `json:"jsonrpc"`
            ID int `json:"id"`
            Result string `json:"result"`
            }





            share|improve this answer





















            • Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
              – Zulhilmi Zainudin
              Nov 10 at 10:08










            • try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
              – Vorsprung
              Nov 10 at 10:10










            • I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
              – Zulhilmi Zainudin
              Nov 10 at 10:13










            • add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
              – Vorsprung
              Nov 10 at 10:19













            up vote
            0
            down vote










            up vote
            0
            down vote









            Your response struct doesn't show the data that the json of the response has



            try this



            type response struct {
            Jsonrpc string `json:"jsonrpc"`
            ID int `json:"id"`
            Result string `json:"result"`
            }





            share|improve this answer












            Your response struct doesn't show the data that the json of the response has



            try this



            type response struct {
            Jsonrpc string `json:"jsonrpc"`
            ID int `json:"id"`
            Result string `json:"result"`
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 10:02









            Vorsprung

            22.1k31941




            22.1k31941












            • Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
              – Zulhilmi Zainudin
              Nov 10 at 10:08










            • try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
              – Vorsprung
              Nov 10 at 10:10










            • I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
              – Zulhilmi Zainudin
              Nov 10 at 10:13










            • add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
              – Vorsprung
              Nov 10 at 10:19


















            • Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
              – Zulhilmi Zainudin
              Nov 10 at 10:08










            • try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
              – Vorsprung
              Nov 10 at 10:10










            • I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
              – Zulhilmi Zainudin
              Nov 10 at 10:13










            • add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
              – Vorsprung
              Nov 10 at 10:19
















            Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
            – Zulhilmi Zainudin
            Nov 10 at 10:08




            Thank you for your help. Unfortunately, I still get json: cannot unmarshal string into Go value of type main.response error.
            – Zulhilmi Zainudin
            Nov 10 at 10:08












            try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
            – Vorsprung
            Nov 10 at 10:10




            try tweaking the response. I didn't look at the library you are using it might strip off the jsonrpc or the id
            – Vorsprung
            Nov 10 at 10:10












            I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
            – Zulhilmi Zainudin
            Nov 10 at 10:13




            I tried. I commented the Jsonrpc. It failed. Next I uncommented Jsonrpc and commented ID. It still failed.
            – Zulhilmi Zainudin
            Nov 10 at 10:13












            add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
            – Vorsprung
            Nov 10 at 10:19




            add at lline 277 of go-ethereum client.go to printf("%v",resp.Result) just before it trips the error. See what it is returning
            – Vorsprung
            Nov 10 at 10:19










            up vote
            0
            down vote













            json: cannot unmarshal string into Go value of type main.response error. I got similar type error when i was unmarshaling a response. It was because the response was actually json string, i mean it had Quotation " as first character. So to be sure you also encountered the same problem, please printf("%v",resp.Result) before unmarshaling in here https://github.com/ethereum/go-ethereum/blob/1ff152f3a43e4adf030ac61eb5d8da345554fc5a/rpc/client.go#L278.






            share|improve this answer

























              up vote
              0
              down vote













              json: cannot unmarshal string into Go value of type main.response error. I got similar type error when i was unmarshaling a response. It was because the response was actually json string, i mean it had Quotation " as first character. So to be sure you also encountered the same problem, please printf("%v",resp.Result) before unmarshaling in here https://github.com/ethereum/go-ethereum/blob/1ff152f3a43e4adf030ac61eb5d8da345554fc5a/rpc/client.go#L278.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                json: cannot unmarshal string into Go value of type main.response error. I got similar type error when i was unmarshaling a response. It was because the response was actually json string, i mean it had Quotation " as first character. So to be sure you also encountered the same problem, please printf("%v",resp.Result) before unmarshaling in here https://github.com/ethereum/go-ethereum/blob/1ff152f3a43e4adf030ac61eb5d8da345554fc5a/rpc/client.go#L278.






                share|improve this answer












                json: cannot unmarshal string into Go value of type main.response error. I got similar type error when i was unmarshaling a response. It was because the response was actually json string, i mean it had Quotation " as first character. So to be sure you also encountered the same problem, please printf("%v",resp.Result) before unmarshaling in here https://github.com/ethereum/go-ethereum/blob/1ff152f3a43e4adf030ac61eb5d8da345554fc5a/rpc/client.go#L278.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 17:39









                nightfury1204

                1,40248




                1,40248






















                    up vote
                    0
                    down vote













                    If you look at the client library code, you'll see that the JSON RPC response object is already disassembled and either an error is returned on failure, or the actual result parsed: https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go#L277



                    The parser however already unwrapped the containing "result" field. Your type still wants to do an additional unwrap:



                    type response struct {
                    Result string
                    }


                    Drop the outer struct, simply pass a string pointer to the client.Call's first parameter.






                    share|improve this answer





















                    • Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
                      – Zulhilmi Zainudin
                      Nov 12 at 10:55

















                    up vote
                    0
                    down vote













                    If you look at the client library code, you'll see that the JSON RPC response object is already disassembled and either an error is returned on failure, or the actual result parsed: https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go#L277



                    The parser however already unwrapped the containing "result" field. Your type still wants to do an additional unwrap:



                    type response struct {
                    Result string
                    }


                    Drop the outer struct, simply pass a string pointer to the client.Call's first parameter.






                    share|improve this answer





















                    • Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
                      – Zulhilmi Zainudin
                      Nov 12 at 10:55















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    If you look at the client library code, you'll see that the JSON RPC response object is already disassembled and either an error is returned on failure, or the actual result parsed: https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go#L277



                    The parser however already unwrapped the containing "result" field. Your type still wants to do an additional unwrap:



                    type response struct {
                    Result string
                    }


                    Drop the outer struct, simply pass a string pointer to the client.Call's first parameter.






                    share|improve this answer












                    If you look at the client library code, you'll see that the JSON RPC response object is already disassembled and either an error is returned on failure, or the actual result parsed: https://github.com/ethereum/go-ethereum/blob/master/rpc/client.go#L277



                    The parser however already unwrapped the containing "result" field. Your type still wants to do an additional unwrap:



                    type response struct {
                    Result string
                    }


                    Drop the outer struct, simply pass a string pointer to the client.Call's first parameter.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 at 8:58









                    Péter Szilágyi

                    1112




                    1112












                    • Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
                      – Zulhilmi Zainudin
                      Nov 12 at 10:55




















                    • Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
                      – Zulhilmi Zainudin
                      Nov 12 at 10:55


















                    Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
                    – Zulhilmi Zainudin
                    Nov 12 at 10:55






                    Sorry @Péter Szilágyi, I'm not very clear. Can you show it in code? Thanks.
                    – Zulhilmi Zainudin
                    Nov 12 at 10:55




















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237759%2fhow-to-correctly-send-rpc-call-using-golang-to-get-smart-contract-owner%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Schultheiß

                    Liste der Kulturdenkmale in Wilsdruff

                    Android Play Services Check