# eth_getCode

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://pharos-mainnet.g.alchemy.com/v2/{apiKey}

Returns the code at a given address.

Reference: https://www.alchemy.com/docs/chains/pharos/pharos-api-endpoints/eth-get-code

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Address | string | Yes | The address of the contract to get code from. |
| Block | string or enum | Yes | The block number, tag, or hash at which to retrieve the code. |

## Result

**Bytecode** (string): The code from the specified address, as a hexadecimal string.

## Example

### Request

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

### Response

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

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://pharos-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_getCode",
  "params": [
    "0xa50a51c09a5c451c52bb714527e1974b686d8e77",
    "latest"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'eth_getCode',
    params: ['0xa50a51c09a5c451c52bb714527e1974b686d8e77', 'latest']
  })
};

fetch('https://pharos-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://pharos-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_getCode",
    "params": ["0xa50a51c09a5c451c52bb714527e1974b686d8e77", "latest"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://pharos-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getCode\",\n  \"params\": [\n    \"0xa50a51c09a5c451c52bb714527e1974b686d8e77\",\n    \"latest\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://pharos-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getCode\",\n  \"params\": [\n    \"0xa50a51c09a5c451c52bb714527e1974b686d8e77\",\n    \"latest\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://pharos-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"eth_getCode\",\n  \"params\": [\n    \"0xa50a51c09a5c451c52bb714527e1974b686d8e77\",\n    \"latest\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: eth_getCode
description: Returns the code at a given address.
params:
  - name: Address
    required: true
    description: The address of the contract to get code from.
    schema:
      title: hex encoded address
      type: string
      pattern: ^0x[0-9a-fA-F]{40}$
  - name: Block
    required: true
    description: The block number, tag, or hash at which to retrieve the code.
    schema:
      title: Block number, tag, or block hash
      description: Identifies a block by explicit number, a predefined tag (e.g., latest/safe/finalized), or a 32-byte block hash.
      anyOf:
        - title: Block number
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
          description: Unsigned integer block height (e.g., 0 for genesis).
        - title: Block tag
          description: A well-known tag such as "latest", "earliest", "pending", "safe", or "finalized".
          type: string
          enum:
            - earliest
            - finalized
            - safe
            - latest
            - pending
        - title: Block hash
          type: string
          pattern: ^0x[0-9a-f]{64}$
          description: 32-byte Keccak hash of the block header identifying a specific block.
result:
  name: Bytecode
  description: The code from the specified address, as a hexadecimal string.
  schema:
    title: hex encoded bytes
    type: string
    pattern: ^0x[0-9a-f]*$
examples:
  - name: eth_getCode example
    params:
      - name: Address
        value: '0xa50a51c09a5c451c52bb714527e1974b686d8e77'
      - name: Block
        value: latest
    result:
      name: Bytecode
      value: '0x60806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f2458114604d57806355241077146071575b600080fd5b348015605857600080fd5b50605f6088565b60408051918252519081900360200190f35b348015607c57600080fd5b506086600435608e565b005b60005481565b60008190556040805182815290517f199cd93e851e4c78c437891155e2112093f8f15394aa89dab09e38d6ca0727879181900360200190a1505600a165627a7a723058209d8929142720a69bde2ab3bfa2da6217674b984899b62753979743c0470a2ea70029'
```
