MetaMask.Blazor icon indicating copy to clipboard operation
MetaMask.Blazor copied to clipboard

send transaction using a custom erc-20 token

Open racs opened this issue 4 years ago • 7 comments

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

racs avatar Dec 21 '21 10:12 racs

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: https://github.com/michielpost/MetaMask.Blazor/blob/72a0016c97a2a50b760c4f96aed214772e4e9a62/MetaMask.Blazor/wwwroot/metaMaskJsInterop.js#L169-L172

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.

michielpost avatar Dec 21 '21 11:12 michielpost

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" } ] })

racs avatar Jul 21 '22 19:07 racs

Hi,

I don't have a sample with parameters. Currently on holiday, so can't have a look now. Will try to create a sample later in August.

On Thu, 21 Jul 2022 at 21:35, Ricardo Alex @.***> wrote:

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" } ] })

— Reply to this email directly, view it on GitHub https://github.com/michielpost/MetaMask.Blazor/issues/9#issuecomment-1191859704, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKBDEBTLY3I3C6FVMOHUQDVVGQ7NANCNFSM5KP4CBCA . You are receiving this because you commented.Message ID: @.***>

michielpost avatar Jul 21 '22 19:07 michielpost

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

michielpost avatar Aug 16 '22 13:08 michielpost

Thank you.I'll test it

racs avatar Aug 16 '22 19:08 racs

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 avatar Oct 29 '22 03:10 racs

Solved

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

racs avatar Oct 29 '22 04:10 racs