Documentation ¶
Index ¶
- func AddressFromPrivateKey(privateKeyHex string) string
- func CreateHTTPRequestWithBody(method string, uri string, body interface{}) (*http.Request, error)
- func GetHTTPClient(timeout time.Duration) *http.Client
- func GetTransactionParams(ctx context.Context, ethClient types.IEthClient, privateKey *ecdsa.PrivateKey, ...) (nonce uint64, gasPrice *big.Int, chainID *big.Int, gasLimit uint64, err error)
- func SendHTTPRequest(c types.IHTTPClient, req *http.Request) (*http.Response, error)
- func SendRPCRequest(connection types.IWSConnection, request interface{}) error
- func SignMessage(domain apitypes.TypedDataDomain, privateKey string, ...) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddressFromPrivateKey ¶
AddressFromPrivateKey derives the Ethereum address from a hexadecimal private key string.
This function takes a hexadecimal string representing an Ethereum private key (with or without the '0x' prefix) and computes the corresponding Ethereum address.
Parameters:
- privateKeyHex: Hexadecimal string representing the Ethereum private key.
Returns:
- string: The Ethereum address derived from the private key.
func CreateHTTPRequestWithBody ¶
CreateHTTPRequestWithBody creates a new HTTP request with a request body.
Parameters:
- method: HTTP method (GET, POST, PUT, DELETE, etc.).
- uri: Request URI.
- body: Request body to be included in the HTTP request. It can be a string, []byte, or any other type that can be marshaled into a valid HTTP request body.
Returns:
- *http.Request: Created HTTP request instance.
- error: Any error encountered during request creation.
func GetHTTPClient ¶
GetHTTPClient initializes a new `http.Client` with custom `http.Transport` and timeout. The `http.Transport` is configured with:
- 100 `MaxIdleConns`
- 100 `MaxConnsPerHost`
- 100 `MaxIdleConnsPerHost`
The timeout for the `http.Client` can be configured via the `time.Duration` parameter.
Parameters:
- timeout: Timeout duration for the `http.Client`.
Returns:
- *http.Client: Configured HTTP client instance.
func GetTransactionParams ¶
func GetTransactionParams( ctx context.Context, ethClient types.IEthClient, privateKey *ecdsa.PrivateKey, from *common.Address, to *common.Address, data *[]byte, ) (nonce uint64, gasPrice *big.Int, chainID *big.Int, gasLimit uint64, err error)
GetTransactionParams retrieves transaction parameters required for sending a transaction.
This function queries the Ethereum network using the provided Ethereum client (`ethClient`) to fetch the following transaction parameters: - Nonce: The transaction count of the sender's address. - GasPrice: The current gas price for the transaction. - ChainID: The ID of the Ethereum chain the transaction will be sent on. - GasLimit: The maximum amount of gas that can be used for the transaction.
Parameters:
- ctx: The context for the Ethereum client operations.
- ethClient: Interface for interacting with the Ethereum blockchain.
- privateKey: The sender's private key for signing the transaction.
- from: The sender's Ethereum address.
- to: The recipient's Ethereum address (optional for contract creation).
- data: The data payload for the transaction (optional).
Returns:
- nonce: The current nonce (transaction count) of the sender's address.
- gasPrice: The current gas price in Wei.
- chainID: The ID of the Ethereum chain.
- gasLimit: The maximum gas limit for the transaction.
- err: Any error encountered during the retrieval of parameters.
func SendHTTPRequest ¶
SendHTTPRequest sends an HTTP request using a provided `http.Client` and returns the response.
Parameters:
- c: Custom HTTP client implementing `types.IHTTPClient`.
- req: HTTP request instance to be sent.
Returns:
- *http.Response: HTTP response received from the server.
- error: Any error encountered during the HTTP request or response handling.
func SendRPCRequest ¶
func SendRPCRequest(connection types.IWSConnection, request interface{}) error
SendRPCRequest sends a RPC request via a WebSocket connection and returns any error encountered.
Parameters:
- connection: WebSocket connection implementing `types.IWSConnection` interface.
- request: JSON-RPC request payload to be sent over the WebSocket connection.
Returns:
- error: Returns an error if there was any issue sending the RPC request.
func SignMessage ¶
func SignMessage(domain apitypes.TypedDataDomain, privateKey string, primaryType types.PrimaryType, message interface{}) (string, error)
SignMessage signs a message using EIP-712 and returns the signature.
This function signs a message using the EIP-712 standard, which defines structured data hashing and signing for Ethereum. It takes the domain parameters (like name, version, chainId, verifyingContract), private key of the signer, primary type (the structure of the message), and the message itself.
Parameters:
- domain: The domain parameters required for EIP-712 signing.
- privateKey: The private key of the signer in hexadecimal format (without '0x' prefix).
- primaryType: The primary type describing the structure of the message being signed.
- message: The message payload to be signed. It should conform to the primaryType structure.
Returns:
- string: The signature of the message in hexadecimal format (with '0x' prefix).
- error: An error if the signing process fails, nil otherwise.
Types ¶
This section is empty.