Expose eth_simulateV1 RPC method via ethclient

This commit is contained in:
Abhay Singh 2025-10-09 20:28:57 +05:30 committed by GitHub
parent 11208553dd
commit 053f58f966
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -36,6 +36,13 @@ type Client struct {
c *rpc.Client
}
// SimulateV1 calls the eth_simulateV1 RPC method.
func (ec *Client) SimulateV1(ctx context.Context, opts map[string]interface{}, blockParam string) (map[string]interface{}, error) {
var result map[string]interface{}
err := ec.c.CallContext(ctx, &result, "eth_simulateV1", opts, blockParam)
return result, err
}
// Dial connects a client to the given URL.
func Dial(rawurl string) (*Client, error) {
return DialContext(context.Background(), rawurl)

View file

@ -754,3 +754,28 @@ func ExampleRevertErrorData() {
// revert: 08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a75736572206572726f72
// message: user error
}
// Test for SimulateV1
func TestSimulateV1(t *testing.T) {
client := ethclient.NewClient(rpc.DialContext)
opts := map[string]interface{}{
"traceTransfers": true,
"validation": true,
"blockStateCalls": []interface{}{
map[string]interface{}{
"calls": []interface{}{
map[string]interface{}{
"from": "0x...",
"to": "0x...",
"data": "0x...",
},
},
},
},
}
resp, err := client.SimulateV1(context.Background(), opts, "latest")
if err != nil {
t.Fatalf("SimulateV1 failed: %v", err)
}
t.Logf("Response: %+v", resp)
}