đ 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
30
31
32
33
<?php
# ----- REPLACE THE VARIABLES BELOW WITH YOUR DATA -----
$apikey = "YOURAPIKEY"; // API Key in your account panel
$contractaddress = "CONTRACTADDRESS"; // Smart contract address of the Token
$from = "SENDERADDRESS"; // Polygon address you want to send from (must have been created with Chaingateway.io)
$to = "RECEIVERADDRESS"; // Receiving polygon address
$password = "PASSWORD"; // Password of the polygon address (which you specified when you created the address)
$amount = 55.89; // Amount of Tokens to send
# -------------------------------------------------------
$ch = curl_init("https://api.chaingateway.io/v2/polygon/balances/".$polygonaddress."/erc20/".$contractaddress);
# Setup request to send json via POST. This is where all parameters should be entered.
$payload = json_encode( array("contractaddress" => $contractaddress, "from" => $from, "to" => $to, "password" => $password, "amount" => $amount) );
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;