diff --git a/examples/send-multioperator-orderflow/main.go b/examples/send-multioperator-orderflow/main.go index 2ed3765..c495944 100644 --- a/examples/send-multioperator-orderflow/main.go +++ b/examples/send-multioperator-orderflow/main.go @@ -18,9 +18,10 @@ import ( ) var ( - // Builder node endpoint and certificate - endpoint = "https://127.0.0.1:443" - certPEM = []byte("-----BEGIN CERTIFICATE-----\nMIIBlTCCATugAwIBAgIQeUQhWmrcFUOKnA/HpBPdODAKBggqhkjOPQQDAjAPMQ0w\nCwYDVQQKEwRBY21lMB4XDTI0MTExNDEyMTExM1oXDTI1MTExNDEyMTExM1owDzEN\nMAsGA1UEChMEQWNtZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJCl4R+DtNqu\nyPYd8a+Ppd4lSIEgKcyGz3Q6HOnZV3D96oxW03e92FBdKUkl5DLxTYo+837u44XL\n11OWmajjKzGjeTB3MA4GA1UdDwEB/wQEAwIChDATBgNVHSUEDDAKBggrBgEFBQcD\nATAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTjt0S4lYkceJnonMJBEvwjezh3\nvDAgBgNVHREEGTAXgglsb2NhbGhvc3SHBDSuK4SHBH8AAAEwCgYIKoZIzj0EAwID\nSAAwRQIgOzm8ghnR4cKiE76siQ43Q4H2RzoJUmww3NyRVFkcp6oCIQDFZmuI+2tK\n1WlX3whjllaqr33K7kAa9ntihWfo+VB9zg==\n-----END CERTIFICATE-----\n") + // Builder node nodeEndpoint and certificate + nodeEndpoint = "https://127.0.0.1:443" + nodeCertPEM = []byte("-----BEGIN CERTIFICATE-----\nMIIBlTCCATugAwIBAgIQeUQhWmrcFUOKnA/HpBPdODAKBggqhkjOPQQDAjAPMQ0w\nCwYDVQQKEwRBY21lMB4XDTI0MTExNDEyMTExM1oXDTI1MTExNDEyMTExM1owDzEN\nMAsGA1UEChMEQWNtZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJCl4R+DtNqu\nyPYd8a+Ppd4lSIEgKcyGz3Q6HOnZV3D96oxW03e92FBdKUkl5DLxTYo+837u44XL\n11OWmajjKzGjeTB3MA4GA1UdDwEB/wQEAwIChDATBgNVHSUEDDAKBggrBgEFBQcD\nATAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTjt0S4lYkceJnonMJBEvwjezh3\nvDAgBgNVHREEGTAXgglsb2NhbGhvc3SHBDSuK4SHBH8AAAEwCgYIKoZIzj0EAwID\nSAAwRQIgOzm8ghnR4cKiE76siQ43Q4H2RzoJUmww3NyRVFkcp6oCIQDFZmuI+2tK\n1WlX3whjllaqr33K7kAa9ntihWfo+VB9zg==\n-----END CERTIFICATE-----\n") + ignoreNodeCert = false // if set to true, the client will ignore the server certificate and connect to the endpoint without verifying it // Transaction and signing key rawTxHex = "0x02f8710183195414808503a1e38a30825208947804a60641a89c9c3a31ab5abea2a18c2b6b48408788c225841b2a9f80c080a0df68a9664190a59005ab6d6cc6b8e5a1e25604f546c36da0fd26ddd44d8f7d50a05b1bcfab22a3017cabb305884d081171e0f23340ae2a13c04eb3b0dd720a0552" @@ -40,24 +41,35 @@ func createTransportForSelfSignedCert(certPEM []byte) (*http.Transport, error) { }, nil } -func exampleSendRawTx() error { - requestSigner, err := signature.NewSignerFromHexPrivateKey(signerPrivateKey) - if err != nil { - return err +func exampleSendRawTx() (err error) { + // Create a transport that verifies (or ignores) the server certificate + var transport *http.Transport + if ignoreNodeCert { + transport = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + } else { + transport, err = createTransportForSelfSignedCert(nodeCertPEM) + if err != nil { + return err + } } - transport, err := createTransportForSelfSignedCert(certPEM) + // Prepare the request signer + requestSigner, err := signature.NewSignerFromHexPrivateKey(signerPrivateKey) if err != nil { return err } - client := rpcclient.NewClientWithOpts(endpoint, &rpcclient.RPCClientOpts{ + // Setup the RPC client + client := rpcclient.NewClientWithOpts(nodeEndpoint, &rpcclient.RPCClientOpts{ HTTPClient: &http.Client{ Transport: transport, }, Signer: requestSigner, }) + // Execute the eth_sendRawTransaction request rawTransaction := hexutil.MustDecode(rawTxHex) resp, err := client.Call(context.Background(), "eth_sendRawTransaction", rpctypes.EthSendRawTransactionArgs(rawTransaction)) if err != nil {