> ## Documentation Index
> Fetch the complete documentation index at: https://docs.etherscan.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Contract Source Code

> Retrieve the source code for a verified smart contract.

export const chain = '1';

<ResponseExample>
  ```json Example response theme={null}
  {
    "status": "1",
    "message": "OK",
    "result": [
      {
        "SourceCode": "pragma solidity 0.4.26;\r\n\r\ncontract Test12345 {\r\n    string public test;\r\n    \r\n    function enterValue(string _c) {\r\n        test = _c;\r\n    }\r\n}",
        "ABI": "[{\"constant\":false,\"inputs\":[{\"name\":\"_c\",\"type\":\"string\"}],\"name\":\"enterValue\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]",
        "ContractName": "Test12345",
        "CompilerVersion": "v0.4.26+commit.4563c3fc",
        "CompilerType": "solc",
        "OptimizationUsed": "1",
        "Runs": "200",
        "ConstructorArguments": "",
        "EVMVersion": "Default",
        "Library": "",
        "ContractFileName": "",
        "LicenseType": "None",
        "Proxy": "0",
        "Implementation": "",
        "SwarmSource": "bzzr://f6b932198e10e83a6c872406a4252cf5eea48f37bac9a33085eba887820370cf",
        "SimilarMatch": "0x60810f4d8a618edb533a168e790ab6c09b0e7707"
      }
    ]
  }
  ```
</ResponseExample>


## OpenAPI

````yaml openapi/api-reference/endpoint/getsourcecode.json GET /v2/api
openapi: 3.1.0
info:
  title: Get Contract Source Code
  version: 2.0.0
  description: Retrieve the source code for a verified smart contract.
  license:
    name: Etherscan API Terms
    url: https://etherscan.io/terms
servers:
  - url: https://api.etherscan.io
    description: Etherscan API.
security:
  - apiKey: []
paths:
  /v2/api:
    get:
      summary: Get Contract Source Code
      description: Retrieve the source code for a verified smart contract.
      operationId: getGetsourcecode
      parameters:
        - name: chainid
          in: query
          required: true
          description: >-
            Chain ID to query, eg 1 for Ethereum, 42161 for Arbitrum from our
            [supported chains](/supported-chains).
          schema:
            type: string
          example: '1'
        - name: module
          in: query
          required: true
          description: Set to contract for this endpoint.
          schema:
            type: string
            default: contract
          example: contract
        - name: action
          in: query
          required: true
          description: Set to getsourcecode for this endpoint.
          schema:
            type: string
            default: getsourcecode
          example: getsourcecode
        - name: address
          in: query
          required: true
          description: The contract address to query.
          schema:
            type: string
          example: '0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    description: >-
                      1 if the request returned data, 0 otherwise. A status of 0
                      can indicate an error or a valid request that returned no
                      records.
                  message:
                    type: string
                    description: >-
                      OK on success, otherwise an error description such as
                      NOTOK. See [common error
                      messages](/common-error-messages).
                  result:
                    type: array
                    items:
                      type: object
                      properties:
                        SourceCode:
                          type: string
                          description: >-
                            Verified source code of the contract. Empty if the
                            contract is not verified.
                        ABI:
                          type: string
                          description: >-
                            Contract ABI as a JSON-encoded string. Returns an
                            error message if the contract is not verified.
                        ContractName:
                          type: string
                          description: Name of the contract.
                        CompilerVersion:
                          type: string
                          description: Compiler version used to compile the contract.
                        CompilerType:
                          type: string
                          description: Type of compiler used, such as solc or vyper.
                        OptimizationUsed:
                          type: string
                          description: >-
                            1 if optimization was enabled during compilation, 0
                            otherwise.
                        Runs:
                          type: string
                          description: >-
                            Number of optimizer runs configured during
                            compilation.
                        ConstructorArguments:
                          type: string
                          description: >-
                            ABI-encoded constructor arguments used at
                            deployment.
                        EVMVersion:
                          type: string
                          description: >-
                            Target EVM version used during compilation. Default
                            if unset.
                        Library:
                          type: string
                          description: Libraries linked during compilation. Empty if none.
                        ContractFileName:
                          type: string
                          description: >-
                            File name of the main source file, for multi-file
                            verifications.
                        LicenseType:
                          type: string
                          description: License declared for the source code.
                        Proxy:
                          type: string
                          description: 1 if the contract is a proxy, 0 otherwise.
                        Implementation:
                          type: string
                          description: >-
                            Address of the implementation contract, if this is a
                            proxy.
                        SwarmSource:
                          type: string
                          description: >-
                            Swarm source hash of the compiler metadata, if
                            present.
                        SimilarMatch:
                          type: string
                          description: >-
                            Address of a verified contract with matching source
                            code, if matched by similarity.
      security:
        - apiKey: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: query
      name: apikey
      description: >-
        Enter your Etherscan API key, or [set one up](/set-up-your-api-key) if
        you don't have one.

````