Skip to content

Commit

Permalink
Golang Base Sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz committed Jul 10, 2024
1 parent be545c0 commit c1b8dc5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1,158 deletions.
2 changes: 1 addition & 1 deletion Scripts/go/contracts/store.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"anonymous":false,"inputs":[],"name":"setEvent","type":"event"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"storedData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
[{"anonymous":false,"inputs":[],"name":"setEvent","type":"event"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"storedData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
2 changes: 1 addition & 1 deletion Scripts/go/contracts/store.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
608060405234801561001057600080fd5b50610179806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632a1afcd91461003b57806360fe47b114610059575b600080fd5b610043610075565b60405161005091906100ca565b60405180910390f35b610073600480360381019061006e9190610116565b61007b565b005b60005481565b806000819055507f24a4f809cc1bf5b0f3c16b615535b56a0b583b1630e06e32b46b759b8088a95d60405160405180910390a150565b6000819050919050565b6100c4816100b1565b82525050565b60006020820190506100df60008301846100bb565b92915050565b600080fd5b6100f3816100b1565b81146100fe57600080fd5b50565b600081359050610110816100ea565b92915050565b60006020828403121561012c5761012b6100e5565b5b600061013a84828501610101565b9150509291505056fea26469706673582212204cdfca4a86b326a9bb2935aebaa08119e8b78e35dc36cff4af6ef2d287894d0164736f6c63430008120033
0x608060405234801561000f575f80fd5b5060043610610034575f3560e01c80632a1afcd91461003857806360fe47b114610056575b5f80fd5b610040610072565b60405161004d91906100c4565b60405180910390f35b610070600480360381019061006b919061010b565b610077565b005b5f5481565b805f819055507f24a4f809cc1bf5b0f3c16b615535b56a0b583b1630e06e32b46b759b8088a95d60405160405180910390a150565b5f819050919050565b6100be816100ac565b82525050565b5f6020820190506100d75f8301846100b5565b92915050565b5f80fd5b6100ea816100ac565b81146100f4575f80fd5b50565b5f81359050610105816100e1565b92915050565b5f602082840312156101205761011f6100dd565b5b5f61012d848285016100f7565b9150509291505056fea2646970667358221220fea330a7cec10cc48673a61fa4e70c4730d778a8eff8b6ffed4b77b209a03d9964736f6c634300081a0033
2 changes: 1 addition & 1 deletion Scripts/go/contracts/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 29 additions & 7 deletions Scripts/go/getSetEvent.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//Step 1: Create abi file by running: solc --abi Store.sol > store.abi
//Step 2: Create bin file by running: solc --bin Store.sol > store.bin
//Step 3: Remove comments above the abi and bin files.
//Step 4: Generate Go contract interaction file by running: abigen --bin=store.bin --abi=store.abi --pkg=store --out=store.go
//Step 5: Run: getSetEvent.go
//Step 1: Install Geth to get abigen
// https://guides.quicknode.com/guides/infrastructure/node-setup/how-to-install-and-run-a-geth-node#installing-geth
//Step 2: Create abi file by running:
// solc --abi Store.sol > store.abi
//Step 3: Create bin file by running:
// solc --bin Store.sol > store.bin
//Step 4: Remove comments above the abi and bin files.
//Step 5: Generate Go contract interaction file by running:
// abigen --bin=store.bin --abi=store.abi --pkg=store --out=store.go
//Step 6: Run:
// go run getSetEvent.go
package main

import (
Expand Down Expand Up @@ -32,11 +38,27 @@ func main() {
// Use this endpoint when you are running your own node on a specific chain (events allowed)
// client, chainID := clientSetup("ws://localhost:8546")

client, chainID := clientSetup(os.Getenv("sepoliaInfuraWSS"))
client, chainID := clientSetup(os.Getenv("baseSepoliaWSS"))
// client, chainID := clientSetup(os.Getenv("sepoliaInfuraWSS"))

fmt.Println("chainID: ", chainID)

contractAddress := common.HexToAddress("0xBBE97Afb978E19033e0BDa692E6034F5b3B91312")
baseSepoliaChainId := big.NewInt(84532);

// fmt.Println("baseSepoliaChainId: ", baseSepoliaChainId)

// // WE CAN'T COMPARE TYPE *big.Int VALUES DIRECTLY! NEED TO USE A HELPER METHOD.
// fmt.Println(baseSepoliaChainId == chainID)

// https://stackoverflow.com/a/44697073
isClientChainIdCorrect := baseSepoliaChainId.Cmp(chainID) == 0;

if isClientChainIdCorrect == false {
fmt.Printf("RPC endpoint not connected to Base Sepolia (chainId: %s)\n", baseSepoliaChainId)
log.Fatal("Switch to Base Sepolia then try again.", )
}

contractAddress := common.HexToAddress("0xeD62F27e9e886A27510Dc491F5530996719cEd3d")
contract := connectContractAddress(client,contractAddress)
fmt.Println("contract type object: ")
fmt.Printf("%T",contract)
Expand Down
38 changes: 34 additions & 4 deletions Scripts/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
module storeProject

go 1.13
go 1.22.5

require (
github.com/ethereum/go-ethereum v1.13.15
github.com/gorilla/websocket v1.5.0
golang.org/x/crypto v0.17.0
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/ethereum/go-ethereum v1.13.15
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/gorilla/websocket v1.5.0
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
golang.org/x/crypto v0.17.0
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.15.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit c1b8dc5

Please sign in to comment.