Ethereum API and its usage

Ethereum API and its usage

Blockchain Ethereum

Crypto APIs Team

Jan 27, 2020 • 3 min

In case you have encountered our Bitcoin endpoints, you’ll feel comfortable right away with our Ethereum API as they are both part of distributed public blockchain networks. However, there are a couple of contrasts to be noted between Bitcoin and Ethereum, driven by their usage purposes. While Bitcoin enables online Bitcoin payments through its electronic cash system, Ethereum leads to the building and deployment of dApps.

Whereas the Bitcoin blockchain was purely a list of transactions, Ethereum’s basic unit is the account. The Ethereum blockchain tracks the state of every account, and all state transitions on the Ethereum blockchain are transfers of value and information between accounts. There are two types of accounts:

  • - Externally Owned Accounts (EOAs), which are controlled by private keys
  • - Contract Accounts, which are controlled by their contract code and can only be “activated” by an EOA

Address endpoint

Crypto APIs Address API allows you to look up information about public Ethereum addresses/accounts and generate your own low-value Ethereum addresses/public-private key pairs. The users doesn’t need to put any information with this POST request for generating addresses.

Our tips on this endpoint:

  • - The private key returned is immediately discarded by our servers, but we advise that these keys should not be used for any high-value—or long-term storage—addresses.
  • - Always use HTTPS for Address Generation requests. Otherwise, your generated private keys will be sent over insecure channels and could be MITM’d.

In addition, the returned object will contain a private key in hex-encoded, a public key, and a public address.

Transactions endpoint

Unlike Bitcoin, Ethereum has no concept of UTXOs (check more on our glossary if unfamiliar). Instead, addresses have a running balance, and use an ever-increasing sequence/nonce for every transaction to maintain proper address state. In order to create a transaction, you should have an account(keystore file) stored on our servers, and then provide the from address, to address, value to transfer (in Ether), gas price and gas limit (at least 21,000 wei), nonce(optional) and data(optional). The user should also specify the password associated with the keyfile, in order to unlock the account.

This query will use the addresses within your wallet as the inputs, as if all of them had been placed within the addresses array. Then, the user receives a transaction hash, such as:

{ “payload”: { “hex”: “0xfebf0691cc92f67ace032897a83587c44c5b2ef437341c6cfd5dbf1f8f4c288d” } }

 It signs the raw transaction with the given parameters and pushes to the Ethereum Blockchain.

Moreover, we provide other endpoints that help provide information if you are not sure whether your gasLimit is enough to make a transaction or what is the average gasPrice,.

Contracts endpoint

Firstly, the concept of contracts represents one of Ethereum’s essential values. The main programming language for building such application is Solidity, which is a decent starting point if you haven’t been creating smart contracts before.

Secondly, The Deploy Smart Contract Endpoint allows you to push your smart contract to the Ethereum Blockchain. You can validate and compile your smart contract to bytecode at the Ethereum official website – Solidity IDE following these steps:

  1. Provide the code by going to Compile
  2. Choose the name of the contract
  3. Go to Details
  4. Go to BYTECODE
  5. Copy the object property (hexadecimal number)

A private key (associated with a funded Ethereum external account), fromAddress, byteCode, gasPrice and gasLimit, to publish, Crypto APIs will embed the contract into the blockchain and return the transaction hash that created the contract.

Finally, The response will be date and hash of the transaction:

{ “payload”: { “hex”: “0xf24889df3b88f8bfe2898a41ecab8ec62b60839a22eec606afe3dff9025b86f6” }

It is very important to provide enough gas in order the transaction to be successful!

These are a few examples of how endpoints help in integrating the Ethereum API into your website. They provide the backbone into the complete process of building, deploying dApps and much more.

Related articles

Share