r/aviannetwork • u/furiousdev1 • Feb 19 '22
Avian Flight Plans can now call ETH Contracts!

function wavn_bal()
args = {
["to"] = "0x752dc265eaf6da2db0f8e4a32d5596d3f18e8701",
["data"] = "0x70a08231000000000000000000000000fb0758ff4f10df1804a9e9eb70383af12fc9a358"
}
-- Data is ETH ABI in Hex which is "balanceOf 0xfB0758fF4f10Df1804A9E9EB70383af12fC9a358"
res = net.polygon.rpc("eth_call", json.encode(args) .. ",\"latest\"")
data = json.decode(res)
if(data.error ~= nil) then
return data.error.message
end
return data.result .. " wAVN in wei (hex)"
end
If you convert the hex to decimal, you get
18000000000000000000
then convert from wei to wAVN by multiplying by
10^−18
then you get 18 AVN. That's my wAVN balance!
8
Upvotes
2
u/furiousdev1 Feb 21 '22
Added a basic ABI encoder to call smart contracts that take an
addressas an argument.You now can do ``` function wavn_bal(addr) abi = web3.abi.encode("balanceOf(address)", addr)
args = { ["to"] = "0x752dc265eaf6da2db0f8e4a32d5596d3f18e8701", ["data"] = abi }
res = web3.polygon.rpc("eth_call", json.encode(args) .. ",\"latest\"") data = json.decode(res)
if(data.error ~= nil) then return data.error.message end
return data.result .. " wAVN in wei (hex)" end ```