Created
April 16, 2025 06:22
-
-
Save thaarok/a87036e17b72978867f69f3434fc1384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/ethereum/go-ethereum/accounts/abi/bind" | |
"github.com/ethereum/go-ethereum/accounts/keystore" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/common/hexutil" | |
"github.com/ethereum/go-ethereum/core/types" | |
"github.com/ethereum/go-ethereum/ethclient" | |
"golang.org/x/term" | |
"math/big" | |
"os" | |
"strings" | |
"syscall" | |
) | |
func main() { | |
client1, err := ethclient.Dial("wss://rpc.blaze.soniclabs.com") | |
if err != nil { | |
panic(err) | |
} | |
defer client1.Close() | |
keystoreData, err := os.ReadFile("./relay.json") | |
if err != nil { | |
panic(err) | |
} | |
var passphrase []byte | |
fmt.Printf("Keystore passphrase: ") | |
passphrase, err = term.ReadPassword(syscall.Stdin) | |
fmt.Printf("\n") | |
if err != nil { | |
panic(err) | |
} | |
key, err := keystore.DecryptKey(keystoreData, strings.TrimSpace(string(passphrase))) | |
if err != nil { | |
panic(err) | |
} | |
contractAddr := common.HexToAddress("0x2ee3dc3c0B4E055984D5a42849d329340A43672E") | |
nonce, err := client1.PendingNonceAt(context.Background(), key.Address) | |
if err != nil { | |
panic(err) | |
} | |
baseTx := &types.DynamicFeeTx{ | |
To: &contractAddr, | |
Nonce: nonce, | |
GasFeeCap: big.NewInt(1050e6), | |
GasTipCap: big.NewInt(1), | |
Gas: 45000, | |
Value: big.NewInt(0), | |
Data: hexutil.MustDecode("0x6057361d0000000000000000000000000000000000000000000000000000000000000005"), | |
} | |
rawTx := types.NewTx(baseTx) | |
auth, err := bind.NewKeyedTransactorWithChainID(key.PrivateKey, big.NewInt(57054)) | |
if err != nil { | |
panic(err) | |
} | |
tx, err := auth.Signer(key.Address, rawTx) | |
if err != nil { | |
panic(err) | |
} | |
err = client1.SendTransaction(context.Background(), tx) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Transaction sent: %s (nonce %d)\n", tx.Hash().Hex(), nonce) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment