API

Pull data programmatically from Ethernal

At the moment, only one endpoint is available, if there is some data that you'd like to fetch from the API, please reach out to [email protected], @antoinedc on Discord or @adechevigne on Twitter!

Authentication

To authenticate, you'll need an auth token that you will find on the "Settings" page. The "API" integration needs to be enabled for requests to go through.

Once you've enabled the integration, the token will be displayed below.

Pass it in a token GET parameter to the endpoint you'd like to use.

There is a different token for each workspace.

Endpoints

get
Storage

https://api.tryethernal.com/contracts/:contractAddress/storage?token=xxx&paths[]=["balances", "0x123456789"]
Reads values of the variables of the contract at address contractAddress. This makes available data you'll find in the "Storage" tab in contracts pages through an API. You need to pass an array of arrays, where each element is the path to the variable you want to read. Top level primitives are automatically decoded, you don't need to specify them in the path. If a variable is not found, an error will be returned. Example: If we have a contract with the following variables declared: (address => uint256) balances; uint256 total; And if we want to read the total and the balance for addresses 0x1234 and 0x5678, we would call the following: https://api.tryethernal.com/contracts/0xabcdef/storage?token=xxx&paths[]=["balances", "0x1234"]&paths[]=["balances", "0x5678"] total will always be returned. The response will have two fields: a paths field that returns asked paths, and a storage field that will contains the values. In this case, it would be: { paths: [ ['balances', '0x1234'], ['balances', '0x5678'] ], storage: { balances: { 'Ox1234': '10000', '0x5678': '20000' }, total: '30000' } } You can find more details about variable reading in this section.
Request
Response
Request
Path Parameters
contractAddress
required
string
Address of the contract
Query Parameters
paths
optional
array
Paths of the variables you want to read
token
required
string
Authentication token
Response
200: OK
Returns queried path and variables values.
{
paths: [
['balances', '0x1234'],
['balances', '0x5678']
],
storage: {
balances: {
'Ox1234': '10000',
'0x5678': '20000'
},
total: '30000'
}
}
400: Bad Request
Can return one of the following:
{ message: 'API integration for workspace Hardhat is disabled' }
{ message: 'No contract at 0xabcd in workspace Hardhat' }
{ message: 'API integration for workspace Hardhat is disabled' }
{ message: 'No artifact for contract at 0xabcd in Hardhat' }
{ message: 'No such variable balance' }
401: Unauthorized
Can return one of the following
{ message: 'Failed authentication' }
{ message: 'Missing auth token' }