Interacting with Smart Contracts on EthVigil via REST APIs


You are familiar with deploying contracts via the CLI tool or the web frontend.

OpenAPI Specification

For every contract deployed or verified on EthVigil, it automatically generates REST API endpoints over HTTPS which are available as an OpenAPI Specification.

Get the OpenAPI spec link


ev-cli getoas 0xbbd8cda5503e1df2983f738ad131a2304528e3dd

The contract being used for this guide comes bundled with the CLI tool by the name ERC20MintablePresupplied.sol and implements the standard interface for an ERC20 token contract. The modification introduced is where the Ethereum account that deploys the contract automatically gets a number of minted tokens, 1000000000000000000000000 to be exact.

Web UI

On visiting the contract's dashboard, you can find the OpenAPI spec link on the top left corner with a copy button and as well as right above the name of the contract.

OpenAPI spec link on web UI

Import the OpenAPI spec in Postman

Click on the import button in the top left corner and select the Link tab.

Import EthVigil generated OpenAPI Spec in Postman

You will see the Contract methods populated as HTTP GET and POST endpoints.

Contract methods listing on EthVigil

GET HTTP endpoints

EthVigil exposes the following as GET endpoints from the Solidity source code of a smart contract

Let us try out a couple of GET calls on the contract that reads the state data on chain.

Get name of the ERC20 contract

For example, against the public variable name, EthVigil automatically exposes it as a GET endpoint as if it were an accessor.

EthVigil HTTP GET call on smart contract 'name'

Get totalSupply of this ERC20 contract

EthVigil HTTP GET call on smart contract public accessor `totalSupply` This tells us the total tokens in supply through this contract amounts to 1000000000000000000000000.

POST HTTP endpoints

EthVigil exposes the following as POST endpoints from the Solidity source code of a smart contract

Invoke transfer() method

To perform POST calls on EthVigil API, an HTTP header X-API-KEY is also expected. This holds the API key(Write) associated with your EthVigil account

The HTTP request headers are already populated with the necessary parameters, courtesy the tight integration between Postman and OpenAPI Specs. Ensure you put the API key(Write) associated with your account in the header field shown below.

EthVigil HTTP POST call headers with API key for transfer() method

Once entering the necessary body and header request parameters, we complete the HTTP POST to transfer()

EthVigil HTTP POST call body for transfer() method

It returns the transaction hash sent out on the blockchain network corresponding to this request, which is, 0x0be3be1c909087383ff2d6d6cdc0bce3c2c166eda4dd64bfef94c2ac580f819e

Verifying the state changes

We make a call to the public mapping balanceOf on the ERC20 smart contract that holds a mapping of Ethereum addresses to their allocated tokens. Enter the account address to which the transfer was made in the previous section against the path parameter in Postman.

EthVigil HTTP GET call to get balanceOf the address to which transfer was made

As you can see, the transfer has resulted in the balance of 0x008604d4997a15a77f00CA37aA9f6A376E129DC5 to be set to 1000, i.e. the value passed to the transfer method call.