---
title: "eth_getCode"
description: "Returns the code at a given address (Ethereum)"
url: "https://blockreq.com/docs/build/api-reference/ethereum/eth_getCode/"
---

# eth_getCode

**Network:** Ethereum · Mainnet · Chain ID `1` (`0x1`)

**Counts as 1 request.** See [Request Counting](https://blockreq.com/docs/pricing/request-counting/index.md).

Returns code at a given address. Used to check if an address is a smart contract.

## Parameters

1. `DATA` (20 bytes) — Address to get code from.
2. `QUANTITY|TAG` — Block number, or `"latest"`, `"earliest"`, `"pending"`.

## Returns

`DATA` — The code from the given address. Returns `0x` for EOA (non-contract) accounts.

## Request

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "latest"],
  "id": 1
}
```

## Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x6080604052..."
}
```

Replace the example address with a contract on Ethereum.

> If the result is `"0x"`, the address is an EOA (externally owned account), not a contract.

## Code Examples

**cURL**

```bash
curl -X POST https://ethereum-rpc.blockreq.com/v1/rpc/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","latest"],"id":1}'
```

**TypeScript**

```typescript
const response = await fetch("https://ethereum-rpc.blockreq.com/v1/rpc/public", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "latest"
  ],
  "id": 1
}),
});
const data = await response.json();
console.log(data.result);
```

**Python**

```python
import requests

response = requests.post(
    "https://ethereum-rpc.blockreq.com/v1/rpc/public",
    json={
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "latest"
  ],
  "id": 1
}
)
print(response.json()["result"])
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := []byte(`{"jsonrpc":"2.0","method":"eth_getCode","params":["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","latest"],"id":1}`)
	resp, err := http.Post(
		"https://ethereum-rpc.blockreq.com/v1/rpc/public",
		"application/json",
		bytes.NewBuffer(payload),
	)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	var result map[string]interface{}
	json.Unmarshal(body, &result)
	fmt.Println(result["result"])
}
```

**viem**

```typescript
import { createPublicClient, http } from "viem";

const client = createPublicClient({
  transport: http("https://ethereum-rpc.blockreq.com/v1/rpc/public"),
});

const result = await client.request({
  method: "eth_getCode",
  params: ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","latest"],
});
console.log(result);
```

**Foundry**

```bash
cast rpc --rpc-url https://ethereum-rpc.blockreq.com/v1/rpc/public eth_getCode 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 latest
```

**Hardhat**

```javascript
const { ethers } = require("hardhat");

async function main() {
  const provider = new ethers.JsonRpcProvider("https://ethereum-rpc.blockreq.com/v1/rpc/public");
  const result = await provider.send("eth_getCode", ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","latest"]);
  console.log(result);
}

main();
```
