These are chat archives for Nethereum/Nethereum

10th
Aug 2018
Matthew
@ThatSlyGuy
Aug 10 2018 01:46
Hey @juanfranblanco, is there any way to check if an ethereum address is a deployed contract? For example, OpenZeppelin has a function which checks if an address is a contract, but I don't really understand the mechanisms behind it (https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/AddressUtils.sol). Is there anything like this currently in Nethereum? If not, how trivial (or not) would it be to implement something like this? Currently I am resorting to attempting to call a function on an address, but I think there could be a better way but I'm a bit unsure how it could be done.
Enigmatic
@EnigmaticUnreal_twitter
Aug 10 2018 07:16
Hey @ThatSlyGuy
You could check if an address is a contract by using extcodesize
Called through a smart contract acting as a proxy to check.
So most likely it'll be like - Deploy a contract with a function "checkIfSmartContract" which returns a boolean, then using Nethereum you'll be calling that function to see what is being returned.
extcodesize simply checks to see if an address contains any code and returns the size, but this is done through Solidity.
gm23
@DaChampR_twitter
Aug 10 2018 10:06
I'm trying to filter for all transfer events on a contract. Problem is, I get the event when I use the Transfer function, but don't get it when I use transferFrom...
This is the smart contract: 0x583cbbb8a8443b38abcc0c956bece47340ea1367 (it's on Ropsten)
image.png
Above is my code
Juan Blanco
@juanfranblanco
Aug 10 2018 10:08
what is the code
for TransferFrom
gm23
@DaChampR_twitter
Aug 10 2018 10:09
from the smart contract?
Juan Blanco
@juanfranblanco
Aug 10 2018 10:09
i am going to ask the obvious.. (does it raise an event?)
gm23
@DaChampR_twitter
Aug 10 2018 10:09
yes, i checked :)
Juan Blanco
@juanfranblanco
Aug 10 2018 10:09
ah ok :)
gm23
@DaChampR_twitter
Aug 10 2018 10:10
image.png
this is the smart contract's code
Juan Blanco
@juanfranblanco
Aug 10 2018 10:11
another obvious question.. does it transfer succesfully?
this is my tx
so you have you event there
sorry i jumped to another transaction
can you check the transactionReceipt log and see i there?
for that Transaction?
that will confirm firing
gm23
@DaChampR_twitter
Aug 10 2018 10:17
i'll check
Juan Blanco
@juanfranblanco
Aug 10 2018 10:17
then the next step will be to figure out why your filter doesn't get i
gm23
@DaChampR_twitter
Aug 10 2018 10:23
Well this looks weird
image.png
Juan Blanco
@juanfranblanco
Aug 10 2018 10:24
yep no logs.. status?
it seems fine
in etherscan
gm23
@DaChampR_twitter
Aug 10 2018 10:25
status is 1
Juan Blanco
@juanfranblanco
Aug 10 2018 10:25
yeah..
so what has happened is the if / else
so it failed on the else condition
(failed => went through the else condition)
is it allowed ?
gm23
@DaChampR_twitter
Aug 10 2018 10:28
huh. I'll check everything now, thanks. I'll update you with my findings.
dotnet rev
@dotnetrev_gitlab
Aug 10 2018 10:29

I need to get all logs of "Transfer" event of contract. I write the code. But getting error - "Index was outside the bounds of the array." My code is -

            var contract = web3.Eth.GetContract(abiContract, ContractAddress);
            var transferEvent = contract.GetEvent("Transfer");
            var filterAll = transferEvent.CreateFilterInput(new BlockParameter(0), BlockParameter.CreateLatest());
            var log = transferEvent.GetAllChanges<object>(filterAll).GetAwaiter().GetResult();

please help me in this. I am checking it on Ropsten. Thanks in advance.

gm23
@DaChampR_twitter
Aug 10 2018 10:34
@juanfranblanco fascinating, it actually was not allowed. I did send the allow request, but did not check the receipt - it actually failed (out of gas). So that's the problem I guess. Sorry about that. :(
gm23
@DaChampR_twitter
Aug 10 2018 10:39
@dotnetrev_gitlab try this:
transferEvent = Parity.Eth.GetContract(abi, smartContractAddress).GetEvent("Transfer");
eventFilter = transferEvent.CreateFilterAsync(new BlockParameter(0)).Result;

var log = transferEvent.GetAllChanges<Nethereum.StandardTokenEIP20.DTOs.TransferEventDTO>(eventFilter).Result;
Juan Blanco
@juanfranblanco
Aug 10 2018 10:41
@DaChampR_twitter glad is all working
dotnet rev
@dotnetrev_gitlab
Aug 10 2018 10:54
@DaChampR_twitter Thanks. It's Worked. New code -
           var contract = web3.Eth.GetContract(abiContract, ContractAddress);
            var transferEvent = contract.GetEvent("Transfer");
            var filterAll = transferEvent.CreateFilterInput(new BlockParameter(0), BlockParameter.CreateLatest());
            var log = transferEvent.GetAllChanges<Nethereum.StandardTokenEIP20.DTOs.TransferEventDTO>(filterAll).GetAwaiter().GetResult();
Juan Blanco
@juanfranblanco
Aug 10 2018 12:37
@dotnetrev_gitlab @DaChampR_twitter in RC1 you can do something like this now
var eventx = web3.Eth.GetEvent<TransferEventDTO>("contractAddress");
var filter = await eventx.CreateFilterAsync();
var log = await eventx.GetAllChanges(filter);
CreateFilter uses the default blocks Earliest and Latests
the Event is For TransferEventDTO so no need to pass the type again to decode
The event definition is already in the Event so no need to pass the abi
and you can also create an event without a contract address
to get events for different addresses
gm23
@DaChampR_twitter
Aug 10 2018 13:44
cool
gm23
@DaChampR_twitter
Aug 10 2018 13:49
i guess earliest is block 0? Would there be a performance difference If one would put the start at the block number when the smart contract was deployed (since there wouldn't be any difference in the result, obviously)?
Juan Blanco
@juanfranblanco
Aug 10 2018 13:53
well that will depend on the indexing of the different clients
but yeah better safer than sorry and put the deployment block
gm23
@DaChampR_twitter
Aug 10 2018 13:55
is there a quick way to fetch that block automatically (without iterating through the whole blockchain and looking at logs..)?
Juan Blanco
@juanfranblanco
Aug 10 2018 13:56
well if you are only interested in a contract
re-running the filter getchanges will be more than enough at intervals
Juan Blanco
@juanfranblanco
Aug 10 2018 14:04
i will implement subscriptions next for geth (but that is going to take some time)
gm23
@DaChampR_twitter
Aug 10 2018 14:13
nice
userid2018
@userid2018
Aug 10 2018 16:50
@EnigmaticUnreal_twitter just looking at it after a break of 2 days. will come back on if it worked
userid2018
@userid2018
Aug 10 2018 17:06

@EnigmaticUnreal_twitter @juanfranblanco

So i passed the exception part but i am still not getting the Event.I checked the block the event is there.Below is the code with only relevant parts ..

on etherscan we can see the event https://ropsten.etherscan.io/tx/0x0426456cdf8339c1c949d880cbff7752d89adde88ef86297230002eb519e3367#eventlog

Am i missing something ?

class tempClass
{

static async Task MainAsync(string[] args)
{

    try
    {

        var calledContract = web3.Eth.GetContract(CalledContractABI, calledContractAddress);

        var transferEvents = calledContract.GetEvent("TrackingRequest");

        var startBlockNumber = 3797821; //for test
                                        // 3797826  block number event was written on 
        var endBlockNumber = new HexBigInteger(3797900);


        var startBlock = new BlockParameter(new HexBigInteger(startBlockNumber));
        var endBlock = new BlockParameter(endBlockNumber);

        var filterBlockRange = transferEvents.CreateFilterInput(startBlock, endBlock);
        var eventsList = await transferEvents.GetAllChanges<TransferredEvent>(filterBlockRange);

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.WriteLine(ex.InnerException);
    }

}

}

[Event("TransferredEvent")]
public class TransferredEvent : IEventDTO
{
[Parameter("string", "trackingNumber", 1, false)]
public string TrackingNumber { get; set; }
}

Enigmatic
@EnigmaticUnreal_twitter
Aug 10 2018 17:12
Is your smart contract's event name "TransferredEvent", or just "transfer"?
userid2018
@userid2018
Aug 10 2018 17:17

@EnigmaticUnreal_twitter you are spot on. found it and it worked. My Event name was not mactching.

for others benefit here is my solidity contract and c# event class

pragma solidity ^0.4.18;

contract TrackerContract
{

string trackingID;
event TrackingRequest(string trackingNumber);


function setTrackingNumber(string _trackNumber) public  {

    trackingID = _trackNumber;
    emit TrackingRequest(_trackNumber);

}

}

[Event("TrackingRequest")]
public class TransferredEvent : IEventDTO
{
[Parameter("string", "trackingNumber", 1, false)]
public string TrackingNumber { get; set; }
}

Enigmatic
@EnigmaticUnreal_twitter
Aug 10 2018 17:18
Yay! :)