<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sara Valls on Medium]]></title>
        <description><![CDATA[Stories by Sara Valls on Medium]]></description>
        <link>https://medium.com/@saravalls?source=rss-82267ce05f4b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7oYSfmXOj7BJhKsZkCNaIg@2x.jpeg</url>
            <title>Stories by Sara Valls on Medium</title>
            <link>https://medium.com/@saravalls?source=rss-82267ce05f4b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:22:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saravalls/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to call JSON-RPC API using Python]]></title>
            <link>https://saravalls.medium.com/how-to-call-json-rpc-api-using-python-a6bbcbc081d0?source=rss-82267ce05f4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6bbcbc081d0</guid>
            <category><![CDATA[nethermind]]></category>
            <category><![CDATA[starknet]]></category>
            <category><![CDATA[json-rpc-api]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sara Valls]]></dc:creator>
            <pubDate>Sat, 25 Nov 2023 16:21:53 GMT</pubDate>
            <atom:updated>2023-11-25T16:21:53.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*nh0q4URDwImR1rLhMYxK_A.png" /></figure><p>If you’re trying to play with blockchain data, you’ve likely come across JSON-RPC APIs. But don’t worry, calling this type of APIs using Python will take you just a few minutes.</p><p>In this example we will use <a href="https://nethermind.notion.site/Nethermind-s-RPC-Service-for-Starknet-builders-d3a086536b8b477ca1b7fa264a8cf951">Nethermind’s RPC Service for Starknet</a>, which has a free version that doesn’t required API key. Copy and paste the following code in your python environment and that’s it!</p><pre>import requests<br><br># Define the JSON-RPC endpoint URL<br>url = &quot;https://limited-rpc.nethermind.io/mainnet-juno/&quot;<br><br># Define the JSON-RPC method and parameters<br>method = &quot;starknet_specVersion&quot;<br>params = {} <br><br># Create JSON-RPC payload<br>payload = {<br>    &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>    &quot;method&quot;: method,<br>    &quot;params&quot;: params,<br>    &quot;id&quot;: 1,<br>}<br><br># Make the JSON-RPC request using the requests library<br>response = requests.post(url, json=payload)<br><br># Parse the response<br>result = response.json()<br><br># Print the result<br>print(result)</pre><p>If you run it, the response should be:</p><pre>{&#39;jsonrpc&#39;: &#39;2.0&#39;, &#39;result&#39;: &#39;0.5.1&#39;, &#39;id&#39;: 1}</pre><p>Okey, this one was really easy. What about calling and endpoint that needs some params? (For the full lists of enpdoints go to this <a href="https://playground.open-rpc.org/?uiSchema%5BappBar%5D%5Bui:splitView%5D=false&amp;schemaUrl=https://raw.githubusercontent.com/starkware-libs/starknet-specs/master/api/starknet_api_openrpc.json&amp;uiSchema%5BappBar%5D%5Bui:input%5D=false&amp;uiSchema%5BappBar%5D%5Bui:darkMode%5D=true&amp;uiSchema%5BappBar%5D%5Bui:examplesDropdown%5D=false">link</a>).</p><p>Let’s try to call starknet_getClassHashAt method. For that, we need to change method and params variables in our code:</p><pre>method = &quot;starknet_getClassHashAt&quot;<br>params = {<br>    &quot;block_id&quot;: {<br>            &quot;block_number&quot;: 98565,<br>        },<br>    &quot;contract_address&quot;: &#39;0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82&#39;,<br>    } </pre><p>The rest of the code should stay the same, and the response should be:</p><pre>{&#39;jsonrpc&#39;: &#39;2.0&#39;, &#39;result&#39;: &#39;0xd0e183745e9dae3e4e78a8ffedcce0903fc4900beace4e0abf192d4c202da3&#39;, &#39;id&#39;: 1}</pre><p>Awesome! Last but not least, in the case you need to pass an Api key you can adjust the code as following:</p><pre>import requests<br><br># Define the JSON-RPC endpoint URL<br>url = &quot;https://rpc.nethermind.io/mainnet-juno/&quot;<br><br># Define the JSON-RPC method and parameters<br>method = &quot;starknet_specVersion&quot;<br>params = {} <br><br># Create JSON-RPC payload<br>payload = {<br>    &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>    &quot;method&quot;: method,<br>    &quot;params&quot;: params,<br>    &quot;id&quot;: 1,<br>}<br><br>headers = {<br>    &quot;Content-Type&quot;: &quot;application/json&quot;,<br>    &quot;x-apikey&quot;: &quot;your_api_key&quot;,<br>}<br><br># Make the JSON-RPC request using the requests library<br>response = requests.post(url, json=payload, headers=headers)<br><br># Parse the response<br>result = response.json()<br><br># Print the result<br>print(result)</pre><p>It wasn’t that difficult, was it? Now the value of the data depends on you :)</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6bbcbc081d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>