Skip to content

Commit

Permalink
Create SimpleCall Example
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Jul 27, 2023
1 parent a4cfd1c commit 7901da4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/simpleCall/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# use this variable to change the RPC base URL
#INTEGRATION_BASE=http_insert_end_point
11 changes: 11 additions & 0 deletions examples/simpleCall/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module account

go 1.18

require github.com/NethermindEth/starknet.go v0.2.1-0.20220620163912-1db2ca279608
replace github.com/NethermindEth/starknet.go => ../../
require (
github.com/google/go-querystring v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
)
6 changes: 6 additions & 0 deletions examples/simpleCall/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
../..
)
50 changes: 50 additions & 0 deletions examples/simpleCall/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"context"
"fmt"
"os"

"github.com/NethermindEth/starknet.go/rpcv02"
"github.com/NethermindEth/starknet.go/types"
"github.com/NethermindEth/starknet.go/utils"
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/joho/godotenv"
)

var (
name string = "mainnet"
someMainnetContract string = "0x024dE48Fb640DB135B3dc85ef0FE2789e032FbCA2fca54E58aB8dB93ca22F767"
contractMethod string = "getName"
)

func main() {
fmt.Println("Starting simpeCall example")
godotenv.Load(fmt.Sprintf(".env.%s", name))
base := os.Getenv("INTEGRATION_BASE")
c, err := ethrpc.DialContext(context.Background(), base)
if err != nil {
panic(err)
}
clientv02 := rpcv02.NewProvider(c)
fmt.Println("Established connection with the client")

contractAddress, err := utils.HexToFelt(someMainnetContract)
if err != nil {
panic(err)
}

// Make read contract call
tx := rpcv02.FunctionCall{
ContractAddress: contractAddress,
EntryPointSelector: types.GetSelectorFromNameFelt(contractMethod),
}

fmt.Println("Making Call() request")
callResp, err := clientv02.Call(context.Background(), tx, rpcv02.BlockID{Tag: "latest"})
if err != nil {
panic(err.Error())
}

fmt.Println(fmt.Sprintf("Response to %s():%s ", contractMethod, callResp[0]))
}

0 comments on commit 7901da4

Please sign in to comment.