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

send transaction using a custom erc-20 token #9

Open
racs opened this issue Dec 21, 2021 · 7 comments
Open

send transaction using a custom erc-20 token #9

racs opened this issue Dec 21, 2021 · 7 comments

Comments

@racs
Copy link

racs commented Dec 21, 2021

Is it possible to use sendransaction but not for eth but sending matic for example on polygon blockchain?

@michielpost
Copy link
Owner

The MetaMaskService.cs has a GenericRpc method. With this method you can send any command to the ethereum JavaScript object.

It results in this JavaScript call:

var result = await ethereum.request({
method: method,
params: params
});

So yes it's possible. But you need to figure out the code you need to use to send matic or polygon. If these are on other networks, the user needs to select that network in their MetaMask extension.

@racs
Copy link
Author

racs commented Jul 21, 2022

var result = await MetaMaskService.GenericRpc("eth_sendTransaction", parameters);

any idea how to mount the parameters? I have tried lots of combination basically the javascript needs to receive

ethereum
.request({
method: "eth_sendTransaction",
params: [
{
from: SelectedAddress,
to: ContractAddress,
data:
"0xa9059cbb000000000000000000000000e4cc0b4dea52652458d31548643bb90b06af5fa00000000000000000000000000000000000000000000000000b1a2bc2ec50000"
}
]
})

@michielpost
Copy link
Owner

michielpost commented Jul 21, 2022 via email

@michielpost
Copy link
Owner

If you already have the encoded data, like in your example, you can do this:

 var result = await MetaMaskService.SendTransaction(ContractAddress, weiValue, "0xa9059cbb000000000000000000000000e4cc0b4dea52652458d31548643bb90b06af5fa00000000000000000000000000000000000000000000000000b1a2bc2ec50000");

If you want to construct this data string based on a smart contract function call, an example can be found here:
https://github.com/michielpost/MetaMask.Blazor/blob/master/MetaMask.Blazor.SampleApp/Pages/Index.razor.cs#L202-L220

@racs
Copy link
Author

racs commented Aug 16, 2022

Thank you.I'll test it

@racs
Copy link
Author

racs commented Oct 29, 2022

Hello

any idea what is wrong on the last parameter of the function "functionCallEncoder.EncodeRequest" the new object[]... value? when i set it to null it works but not encoding the parameters value the way it is the program just stops and does not encode data

private string GetEncodedFunctionCallInteracao()
        {
            //This example uses Nethereum.ABI to create the ABI encoded string to call a smart contract function
                        
            FunctionABI function = new FunctionABI("safeTransferFrom", false);
                        
            var inputsParameters = new[] {
                    new Parameter("address", "from"),
                    new Parameter("address", "to"),
                    new Parameter("uint256", "id"),
                    new Parameter("uint256", "amount"),
                    new Parameter("bytes", "data")
                };
            function.InputParameters = inputsParameters;

            var functionCallEncoder = new FunctionCallEncoder();

            var data = functionCallEncoder.EncodeRequest(function.Sha3Signature, inputsParameters, new object[] { "0xe4Cc0b4dEa9463F8Fcad31548643bb90b06aF5FA",
                "0x473c4B76f170E650F2C203f09eFE8AD77aE57476",
                "1",
                "1",
                "0x" });

            dataencoded = data;
            
            return data;
        }```

@racs
Copy link
Author

racs commented Oct 29, 2022

Solved

                "0xe4Cc0b4dEa9463F7Fcad31548643bb90b06aF5FA",
                "1",
                "1",
                "0x".HexToByteArray() });

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

2 participants