Last active
November 17, 2022 14:43
-
-
Save svanas/52701899cdece6a312372664aa012ed4 to your computer and use it in GitHub Desktop.
Get the totalSupply() of a token (that is not ether) on the Ethereum blockchain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Client: IWeb3 = TWeb3.Create('https://mainnet.infura.io/v3/your-project-id'); | |
web3.eth.call(Client, '0xB8c77482e45F1F44dE1745F52C74426C631bDD52', 'symbol()', [], procedure(tup: TTuple; err: IError) | |
begin | |
if Assigned(err) then | |
begin | |
TThread.Synchronize(nil, procedure | |
begin | |
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0) | |
end); | |
EXIT; | |
end; | |
const Symbol = tup.ToString; | |
web3.eth.call(Client, '0xB8c77482e45F1F44dE1745F52C74426C631bDD52', 'totalSupply()', [], procedure(str: string; err: IError) | |
begin | |
TThread.Synchronize(nil, procedure | |
begin | |
if Assigned(err) then | |
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0) | |
else | |
ShowMessage(web3.eth.utils.fromWei(str, web3.eth.utils.ether) + ' ' + Symbol); | |
end); | |
end); | |
end); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment