Skip to content

Commit

Permalink
Go cline to post et state and query for a block number
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsuryansh committed Jul 3, 2023
1 parent bdb7c20 commit 688173a
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions EVMStateVoteClient/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"context"
"strconv"
"fmt"
"log"
"github.com/ignite/cli/ignite/pkg/cosmosclient"
"evmstorechain/x/evmstorechain/types"
)

func main() {
ctx := context.Background()
addressPrefix := "cosmosvaloper"

//cosmos client instance
client, err := cosmosclient.New(ctx, cosmosclient.WithAddressPrefix(addressPrefix))
if err!= nil {
log.Fatal(err)
}

accountName := "alice" //posting as alice (initialised during ignite chain serve)

account, err := client.Account(accountName)
if err!= nil {
log.Fatal(err)
}

addr, err := account.Address(addressPrefix)
if err != nil {
log.Fatal(err)
}

// msg to submit a state
var blocknum uint64 = 1
var state uint64 = 12
msg := &types.MsgSubmitEthereumState{
Creator: addr,
Blocknumber: blocknum,
State: state,
}

//broadcast transaction from accountName "alice"
txResp, err := client.BroadcastTx(ctx, account, msg)
if err !=nil {
fmt.Println("here")
log.Fatal(err)
}
fmt.Println("Ethereum State Submited")
fmt.Println(txResp)

// Query
queryClient := types.NewQueryClient(client.Context())
queryResp, err := queryClient.Blockstoragestate(ctx, &types.QueryGetBlockstoragestateRequest{ Blocknumber: strconv.FormatUint(blocknum,10)})
if err!=nil {
log.Fatal(err)
}
fmt.Println(queryResp)
}

0 comments on commit 688173a

Please sign in to comment.