Skip to content

Instantly share code, notes, and snippets.

@svanas
Last active November 17, 2022 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svanas/52701899cdece6a312372664aa012ed4 to your computer and use it in GitHub Desktop.
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
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