首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >氖contract.getPastEvents等效

氖contract.getPastEvents等效
EN

Ethereum用户
提问于 2019-12-01 05:42:36
回答 1查看 620关注 0票数 0

我想询问所有关于与Nethereum的合同的转让。这意味着,最后我想拥有所有的交易,这样我就可以打印一份帐户报表。

我想,在web3.js库中,调用应该类似于合同中的内容:

contract.getPastEvents('Transfer', {fromBlock: 1, toBlock: 'latest'}, callbackFunc)

然而,我并没有在getPastEvents中找到相应的元素。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2019-12-01 22:35:23

Kevin用这个例子回答了这个问题,在Gitter Nethereum中进行了直接对话:

代码语言:javascript
复制
using System;
using System.Numerics;
using System.Threading.Tasks;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3;

internal class Program
{
    // Define event we want to look for
    // Note: in a visual studio project outside of this playground, you have the option to install nuget package
    // Nethereum.StandardTokenEIP20 and add a using Nethereum.StandardTokenEIP20 to provide class TransferEventDTO,
    // instead of defining it here.
    [Event("Transfer")]
    public class TransferEventDTO : IEventDTO
    {
        [Parameter("address", "_from", 1, true)]
        public string From { get; set; }

        [Parameter("address", "_to", 2, true)]
        public string To { get; set; }

        [Parameter("uint256", "_value", 3, false)]
        public BigInteger Value { get; set; }
    }

    private static async Task Main(string[] args)
    {
        var url = "https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c";
        var web3 = new Web3(url);
        // This is the contract address of the DAI Stablecoin v1.0 ERC20 token on mainnet
        // See https://etherscan.io/address/0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359
        var erc20TokenContractAddress = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359";

        var transferEventHandler = web3.Eth.GetEvent(erc20TokenContractAddress);
        // Just examine a few blocks by specifying start and end blocks
        var filter = transferEventHandler.CreateFilterInput(
            fromBlock: new BlockParameter(8450678),
            toBlock: new BlockParameter(8450698));
        var logs = await transferEventHandler.GetAllChanges(filter);

        Console.WriteLine($"Token Transfer Events for ERC20 Token at Contract Address: {erc20TokenContractAddress}");
        foreach (var logItem in logs)
            Console.WriteLine(
                $"tx:{logItem.Log.TransactionHash} from:{logItem.Event.From} to:{logItem.Event.To} value:{logItem.Event.Value}");
    }
}

您还可以看到、编辑和执行这个答案这里

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/77944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档