Query editor
withtransfer_in as (selectsum(cast(value as double)/1e18) as eth_in-- value here is uint256 (large, + numbers with no decimal)-- needs to be converted to double (large + or - numbers with decimals) for accuracyfrom ethereum.traceswhere to = {{Address}}and "type" = 'call'and success = trueand (call_type NOT IN ('delegatecall', 'staticcall', 'callcode') OR call_type is NULL)-- indicates that this should only include calls that change the state of the blockchainand cast(value as double) > 0),transfer_out as (selectsum(cast(value as double)/1e18) as eth_outfrom ethereum.traceswhere "from" = {{Address}}and "type" = 'call'and success = trueand (call_type NOT IN ('delegatecall', 'staticcall', 'callcode') OR call_type is NULL)and cast(value as double) > 0),gas_spent as (selectsum((gas_price_gwei*gas_used)/1e9) as gas_spentfrom gas.feeswhere blockchain = 'ethereum'and tx_sender = {{Address}})select*, eth_in - COALESCE(eth_out, 0) - COALESCE(gas_spent, 0) as balance--Coalesce indicates, if the value in eth_out of gas_spent are NULL, then read that as 0from transfer_in tijoin transfer_out to on 1=1join gas_spent g on 1=1-- 1=1 is saying that there is only one row and we are joining on that one row