@@ -3,14 +3,17 @@ package playground
33import (
44 "context"
55 "crypto/ecdsa"
6+ "crypto/tls"
67 "fmt"
78 "math/big"
9+ "net/http"
810 "time"
911
1012 "github.com/ethereum/go-ethereum/common"
1113 "github.com/ethereum/go-ethereum/core/types"
1214 "github.com/ethereum/go-ethereum/crypto"
1315 "github.com/ethereum/go-ethereum/ethclient"
16+ "github.com/ethereum/go-ethereum/rpc"
1417)
1518
1619// TestTxConfig holds configuration for the test transaction
@@ -23,6 +26,7 @@ type TestTxConfig struct {
2326 GasLimit uint64
2427 GasPrice * big.Int
2528 Timeout time.Duration // Timeout for waiting for receipt. If 0, defaults to 2 minutes
29+ Insecure bool // Skip TLS certificate verification
2630}
2731
2832// DefaultTestTxConfig returns the default test transaction configuration
@@ -69,8 +73,25 @@ func SendTestTransaction(ctx context.Context, cfg *TestTxConfig) error {
6973 elRPCURL = cfg .RPCURL
7074 }
7175
76+ // dialRPC connects to an RPC endpoint, optionally skipping TLS verification
77+ dialRPC := func (url string ) (* ethclient.Client , error ) {
78+ if cfg .Insecure {
79+ httpClient := & http.Client {
80+ Transport : & http.Transport {
81+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
82+ },
83+ }
84+ rpcClient , err := rpc .DialOptions (ctx , url , rpc .WithHTTPClient (httpClient ))
85+ if err != nil {
86+ return nil , err
87+ }
88+ return ethclient .NewClient (rpcClient ), nil
89+ }
90+ return ethclient .Dial (url )
91+ }
92+
7293 // Connect to the EL RPC endpoint (for chain queries)
73- elClient , err := ethclient . Dial (elRPCURL )
94+ elClient , err := dialRPC (elRPCURL )
7495 if err != nil {
7596 return fmt .Errorf ("failed to connect to EL RPC: %w" , err )
7697 }
@@ -79,7 +100,7 @@ func SendTestTransaction(ctx context.Context, cfg *TestTxConfig) error {
79100 // Connect to the target RPC endpoint (for sending transactions)
80101 var targetClient * ethclient.Client
81102 if cfg .RPCURL != elRPCURL {
82- targetClient , err = ethclient . Dial (cfg .RPCURL )
103+ targetClient , err = dialRPC (cfg .RPCURL )
83104 if err != nil {
84105 return fmt .Errorf ("failed to connect to target RPC: %w" , err )
85106 }
0 commit comments