Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode input, checking Function Message before hand. #41

Open
juanfranblanco opened this issue Jul 6, 2021 · 0 comments
Open

Decode input, checking Function Message before hand. #41

juanfranblanco opened this issue Jul 6, 2021 · 0 comments

Comments

@juanfranblanco
Copy link
Member

juanfranblanco commented Jul 6, 2021

using Nethereum.Web3;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts.CQS;
using Nethereum.Util;
using Nethereum.Web3.Accounts;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Contracts;
using Nethereum.Contracts.Extensions;
using System;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;


public class GetStartedSmartContracts
{

    [Function("transfer", "bool")]
    public class TransferFunction : FunctionMessage
    {
        [Parameter("address", "_to", 1)]
        public string To { get; set; }

        [Parameter("uint256", "_value", 2)]
        public BigInteger TokenAmount { get; set; }
    }

    ///*** THE MAIN PROGRAM ***
    public static async Task Main()
    {
		var web3 = new Web3("https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c");
		var txn = await web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync("0x0404a0517a7443db1787b5461b9d5fc18546809419c0cc6a736599b60677ed71");
		if(txn.IsTransactionForFunctionMessage<TransferFunction>()){
			var transfer = new TransferFunction().DecodeTransaction(txn);
			Console.WriteLine(Web3.Convert.FromWei(transfer.TokenAmount));
			Console.WriteLine(transfer.To);
		}

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant