# GetContractByAddress()

### Summary <a href="#summary" id="summary"></a>

| Route                  | Type | Example                                               |
| ---------------------- | ---- | ----------------------------------------------------- |
| /contract/getbyaddress | POST | <http://176.113.80.7:62000/api/contract/getbyaddress> |

### Description <a href="#description" id="description"></a>

Get smart contract source code by its address.

### Request <a href="#request" id="request"></a>

#### Request Structure <a href="#request-structure" id="request-structure"></a>

```json
{

// Parameters common for all requests

"PublicKey": "base58_string", // Smart contract address in Base58
"compressed": "boolean value" // Indicator of data compression true or false

}
```

#### Request Parameters <a href="#request-parameters" id="request-parameters"></a>

string: **PublicKey** - Smart contract address in Base58

bool: **Compressed** - Request compressed data True or False

### Response <a href="#response" id="response"></a>

JSON output depends on the request type and its success.

If there’s an error, request returns to the node basic Result:

* Success: False
* Message:

If successful, requested information is returned.

#### Response Structure <a href="#response-structure" id="response-structure"></a>

```json
{
   "gZipped":"Bytes", // Source code of smart contract Compressed
   "sourceString":"String", // Source code of smart contract in String Value
   "success":"bool", // Shows if request was Succes or False Boolean Value 
   "message":"String" // Shows if a problem occurred with request in String Value
}
```

### Example Code <a href="#example-code" id="example-code"></a>

#### Python

```python
import requests
import json
def Getcontractbyaddres():
    url =  'http://176.113.80.7:62000/api/contract/getbyaddress'
    headers = {
        'Content-type': 'application/json'
        , 'Accept': 'application/json'
        , 'Content-Encoding': 'utf-8'
        }
    data = {
        "NetworkAlias":"Mainnet"
        , "PublicKey":"QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H"
        , "compressed ": False
        }
    answer = requests.post(url, data=json.dumps(data), headers=headers)
    response = answer.json()
    print(response)
Getcontractbyaddres()
```

#### C++

```cpp
#include <iostream>

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams
using namespace web::json;

int main(int argc, char* argv[])
{
    web::json::value json_v;
    web::json::value json_return;
    json_v[L"authKey"] = web::json::value::string(L"");
    json_v[L"NetworkAlias"] = web::json::value::string(L"MainNet");
    json_v[L"PublicKey"] = web::json::value::string(L"QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H");
    json_v[L"compressed"] = web::json::value::boolean(false);

    http_client client(U("http://176.113.80.7:62000"));

    client.request(web::http::methods::POST, U("/api/contract/getbyaddress"), json_v)
        .then([](const web::http::http_response& response) {
        return response.extract_json();
    })
        .then([&json_return](const pplx::task<web::json::value>& task) {
        try {
            json_return = task.get();
        }
        catch (const web::http::http_exception& e) {
            std::cout << "error " << e.what() << std::endl;
        }
    })
        .wait();

    std::wcout << json_return.serialize() << std::endl;

    return 0;
}
```

#### C\#

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Program.Getinfo
{
    public class Getcontractbyaddres
    {
        static readonly HttpClient client = new HttpClient();
        public class body
        {
            public string authKey { get; set; }
            public string networkAlias { get; set; }
            public string PublicKey { get; set; }
            public bool compressed { get; set; }
        }
        public static async Task Main()
        {
            try
            {
                var body = new body
                {
                    authKey = "",
                    networkAlias = "Mainnet",
                    PublicKey = "QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H",
                    compressed = false
                };
                var httpContent = new StringContent(JsonConvert.SerializeObject(body),
                    Encoding.UTF8, "application/json");
                var response = await client.PostAsync("http://176.113.80.7:62000/api/contract/getbyaddress",
                    httpContent);
                Console.WriteLine("RESPONSE=" +
                    await response.Content.ReadAsStringAsync());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.swttoken.com/api-reference/rest-api/getcontractbyaddress.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
