Module: SolanaRpcRuby::RequestBody

Included in:
MethodsWrapper
Defined in:
lib/solana_rpc_ruby/request_body.rb

Instance Method Summary collapse

Instance Method Details

#base_bodyHash

Hash with default body params.

Returns:

  • (Hash)

    hash with base params for every request.


27
28
29
30
31
32
# File 'lib/solana_rpc_ruby/request_body.rb', line 27

def base_body
  {
    "jsonrpc": SolanaRpcRuby.json_rpc_version,
    "id": 1
  }
end

#create_json_body(method, method_params: []) ⇒ Json

Creates body sent to the solana JSON RPC API

From solana docs: To make a JSON-RPC request, send an HTTP POST request with a Content-Type: application/json header. The JSON request data should contain 4 fields: jsonrpc: <string>, set to “2.0” id: <number>, a unique client-generated identifying integer method: <string>, a string containing the method to be invoked params: <array>, a JSON array of ordered parameter values

Parameters:

  • method (string)

    method name.

  • method_params (Array) (defaults to: [])

    ordered array with required and/or optional params.

Returns:

  • (Json)

    JSON string with body.


18
19
20
21
22
23
# File 'lib/solana_rpc_ruby/request_body.rb', line 18

def create_json_body(method, method_params: [])
  body = base_body
  body[:method] = method
  body[:params] = method_params if method_params.any?
  body.to_json
end