rpc.go 778 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "context"
  4. "log"
  5. "github.com/ethereum/go-ethereum"
  6. "github.com/ethereum/go-ethereum/common"
  7. "github.com/ethereum/go-ethereum/ethclient"
  8. )
  9. func main() {
  10. client, _ := ethclient.Dial("http://127.0.0.1:8545")
  11. defer client.Close()
  12. contractAddr := common.HexToAddress("0x8a9009847570fdbcc676c7fd547ab26a358a5005")
  13. myAddress := common.HexToAddress("0x10464a0e69e5bbd01b9bdb7f2943a103a885ff29")
  14. callMsg := ethereum.CallMsg{
  15. To: &contractAddr,
  16. From: myAddress,
  17. Data: common.FromHex("0x"),
  18. }
  19. res, err := client.CallContract(context.Background(), callMsg, nil)
  20. if err != nil {
  21. log.Fatalf("Error calling contract: %v", err)
  22. }
  23. log.Printf(common.BytesToAddress(res).Hex())
  24. }