Sourcify Go is a Golang package that provides tools for interacting with the Sourcify API.
It allows you to access various API endpoints and perform operations such as checking server status, retrieving chains information, obtaining contract information from supported chains and more.
To use Sourcify in your Go project, you can simply import the package:
import "github.com/unpackdev/sourcify-go"
To interact with the Sourcify API, you need to create a client using the NewClient
function. You can provide optional configuration options using ClientOption
functions. For example, you can specify a custom base URL or a custom HTTP client, set retry configuration in case sourcify servers are temporairly unavailable and set rate limits in order to control the rate at which HTTP requests are sent to the sourcify servers.
client := sourcify.NewClient(
sourcify.WithHTTPClient(httpClient),
sourcify.WithBaseURL("https://sourcify.dev/server"),
sourcify.WithRetryOptions(
sourcify.WithMaxRetries(3),
sourcify.WithDelay(2*time.Second),
),
sourcify.WithRateLimit(10, 1*time.Second),
)
Sourcify provides various API endpoints as Method
objects. You can call these endpoints using the CallMethod
function on the client and do your own method parsers if you wish to.
However, if there are methods that we do not provide yet, you can do something like this to extend package.
customMethod := sourcify.Method{...}
customMethod.SetParams(
MethodParam{Key: ":chain", Value: chainId},
)
if err := customMethod.Verify(); err != nil {
return nil, err
}
response, statusCode, err := client.CallMethod(customMethod)
if err != nil {
return nil, err
}
// Close the io.ReadCloser interface.
// This is important as CallMethod is NOT closing the response body!
// You'll have memory leaks if you don't do this!
defer response.Close()
// Process the response
Sourcify provides the following API endpoints that you can call that are currently supported by this package:
MethodHealth
: Check the server status. More informationMethodGetChains
: Retrieve the chains (networks) added to Sourcify. More informationMethodCheckByAddresses
: Check if contracts with the desired chain and addresses are verified and in the repository. More informationMethodCheckAllByAddresses
: Check if contracts with the desired chain and addresses are verified and in the repository. More informationMethodGetFileTreeFullOrPartialMatch
: Get the file tree with full or partial match for the desired chain and address. More informationMethodGetFileTreeFullMatch
: Get the file tree with full match for the desired chain and address. More informationMethodSourceFilesFullOrPartialMatch
: Get the source files with full or partial match for the desired chain and address, including metadata.json. More informationMethodSourceFilesFullMatch
: Get the source files with full match for the desired chain and address, including metadata.json. More informationMethodGetContractAddressesFullOrPartialMatch
: Get the verified contract addresses for the chain with full or partial match. More informationMethodGetFileFromRepositoryFullMatch
: Retrieve statically served files over the server for full match contract. More informationMethodGetFileFromRepositoryPartialMatch
: Retrieve statically served files over the server for partial match contract. More information
For more information on each endpoint, including the parameters they require and the expected responses, refer to the Sourcify API documentation.
You can find endpoint examples under the examples directory.
Contributions to Sourcify are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub.
Sourcify is released under the Apache 2.0 License. See the LICENSE file for more details.