đ Investors Wanted! đ
Join us in our journey to innovate blockchain technologies. Let's shape the future together.
To query the balance of ERC20 tokens, you need a valid Ethereum address. With this tutorial you can easily query the balance of the respective Ethereum address. We have written a detailed tutorial for this purpose. Read more.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
# ----- REPLACE THE VARIABLES BELOW WITH YOUR DATA -----
$apikey = "YOURAPIKEY";
$ethereumaddress = "ETHEREUMADDRESS"; // Ethereum address you want to get the balance of
$contractaddress = "CONTRACTADDRESS"; // Smart contract address of the Token
# -------------------------------------------------------
$ch = curl_init("https://api.chaingateway.io/v2/ethereum/balances/".$ethereumaddress."/erc20/".$contractaddress);
# Setup request to send json via POST. This is where all parameters should be entered.
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST , 'GET' );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Authorization: " . $apikey));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Decode the received JSON string
$resultdecoded = json_decode($result, true);
echo $result;