Ethereum - Getting Started (REST API)
This article covers the steps required to create an Ethereum wallet and generate addresses and private keys. It includes an example of checking the address balance and transferring funds to another Ethereum address.
The following steps and examples are based on Ethereum Sepolia (testnet).
Steps
Step_1: Generate a Mnemonic
Generating a mnemonic means creating a 24-word phrase that will be the foundation for your wallet. This phrase is like a master key from which all your wallet addresses and their private keys can be generated.
- Tatum does not store Mnemonics and or Private Keys.
- The responsibility of keeping your Mnemonics and Private Keys secure rests solely with you, the User.
- Additional information about Mnemonics and Private Keys is available in the following article.
Example request:
- The response returns a Mnemonic and an Ethereum XPUB
curl --location 'https://api.tatum.io/v3/ethereum/wallet' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
"xpub": "xpub6EvVimeVFjj9L6gpcK1qqDCm9dCeRMkLPDsVSRXpCADNSqPL82k6RkwRjZSdP4CxV2raKMEozP3i5QduNRJeZ23ytMfx1x5anGpnqcrH7J2",
"mnemonic": "member aware scale empty track super profit region coast bullet produce describe level best asset walk scan alley merry peanut sweet #### #### ####"
}
Be mindful of Tatum's Derivation Path.
Step_2: Generate an Ethereum Private Key from Mnemonic and index
Creating a private key is creating a unique and secret key that belongs to you. This key is crucial for accessing and controlling your funds.
Example request:
- The response returns an Ethereum Private Key based on index 1.
curl --location 'https://api.tatum.io/v3/ethereum/wallet/priv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"mnemonic": "member aware scale empty track super profit region something bullet produce describe level best asset walk scan alley merry peanut sweet #### #### ####",
"index": 1
}'
//Response:
{
"key": "####"
}
Step_3: Generate an Ethereum address from XPUB and index
Generating an address is about creating a public address where others can send you funds. It's like an account number in the blockchain world.
Example request:
- The response returns an Ethereum Externally Owned Address (EOA) based on index 1
curl --location --request GET 'https://api.tatum.io/v3/ethereum/address/xpub6FLi6DJ35YLx5s8rYFTFqAhtsgLTDW37KBVrRbefthNFqc4quzX6xMhQv2hryMzq58eCs9FivkH6Y9LVviLiXs77SYGBRPbpaB4a6####/1' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
"address": "0xfff67ff286934993821b06687b152734d7907081"
}
Step_4: Add funds to the Ethereum address
- We take the address generated in step_3.
- For testnet, you can get free coins from a faucet.
{
"address": "0xfff67ff286934993821b06687b152734d7907081"
}
Step_5: Check the balance of an Ethereum address
Request example:
- The response returns the balance of an Ethereum address in ETH.
curl --location 'https://api.tatum.io/v3/ethereum/account/balance/0xfff67ff286934993821b06687b152734d7907081' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
"balance": "0.502"
}
Step_6: Estimate the fees of an Ethereum transaction
Tatum Fee estimates endpoints return values in Wei
. Find more about EVM Fee Estimate in the following article.
Request example:
- The response returns an estimation of the potentially required Gas Used via "
GasLimit
" and the "GasPrice
". Additional information is available in the following article.
curl --location 'https://api.tatum.io/v3/ethereum/gas' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"from": "from": "0xfff67ff286934993821b06687b152734d7907081",
"to": "0x5041F19dC1659E33848cc0f77cbF7447de562917",
"amount": "0.001"
}'
//Response:
{
"gasLimit": "21000",
"gasPrice": "38900887981",
"estimations": {
"safe": "38595271624",
"standard": "38595271624",
"fast": "38900887981",
"baseFee": "38289655266"
}
}
Step_7: Check the current "nonce" value from the sender's address
The "nonce
" is a unique and incremental counter used to ensure that each transaction is processed only once, preventing replay attacks. EVM transactions require this. Find more about the "nonce
" in the following article.
Request example:
- The response returns the current "nonce" value of an Ethereum address
curl --location 'https://api.tatum.io/v3/ethereum/transaction/count/0xfff67ff286934993821b06687b152734d7907081' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
0
Step_8: Sign and broadcast an Ethereum transaction
Request example:
- The response returns a transaction hash
curl --location 'https://api.tatum.io/v3/ethereum/transaction' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
"currency": "ETH",
"amount": "0.001",
"fee": {
"gasLimit": "21000",
"gasPrice": "50"
},
"to": "0x5041F19dC1659E33848cc0f77cbF7447de562917",
"nonce": 0,
"fromPrivateKey": "SENDER_ADDRESS_PRIVATE_KEY",
}'
//Response:
{
"txId": "0x4a198d0d4c28a6a092d0e7598691f25f9defd69fe9e284205cd8b826bd6c09a3"
}
Step_9: Get the details of an Ethereum transaction
Request example:
- The response returns the details of an Ethereum transaction hash
curl --location 'https://api.tatum.io/v3/ethereum/transaction/0x4a198d0d4c28a6a092d0e7598691f25f9defd69fe9e284205cd8b826bd6c09a3' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
"transactionHash": "0x4a198d0d4c28a6a092d0e7598691f25f9defd69fe9e284205cd8b826bd6c09a3",
"blockHash": "0x81627d7bb40cdbb398add375b6c39d4457390665ff7b7f46b31b8788b77a6ce9",
"blockNumber": 6238273,
"from": "0xfff67ff286934993821b06687b152734d7907081",
"gas": 21000,
"gasPrice": "50000000000",
"input": "0x",
"nonce": 0,
"to": "0x5041f19dc1659e33848cc0f77cbf7447de562917",
"transactionIndex": 9,
"value": "1000000000000000",
"type": 0,
"chainId": 11155111,
"contractAddress": null,
"cumulativeGasUsed": 371721,
"effectiveGasPrice": 50000000000,
"gasUsed": 21000,
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": true,
"hash": "0x4a198d0d4c28a6a092d0e7598691f25f9defd69fe9e284205cd8b826bd6c09a3",
"maxFeePerGas": null,
"maxPriorityFeePerGas": null
}
Good to Know
- Fee Estimates may fluctuate one way or the other, within seconds.
- Tatum Mainnet Fee Estimates are generally in line with other providers.
- The Testnet Fee Estimate is generally unreliable. Since testnet coins have "no value", users tend to set random amounts greatly skewing the estimates.
- Be mindful of Tatum's derivation path. Find additional information in the following article.
- To transfer tokens on the ETH network, check the following article.
- Familiarize yourself with the Safety & Security Basics in the following article.
Updated 3 months ago