Web3ModalUnity icon indicating copy to clipboard operation
Web3ModalUnity copied to clipboard

WebGL/Wagmi byte types are serialized as base64

Open thirdheronet opened this issue 2 years ago • 0 comments

Hello dev/s,

Describe the bug bytes are serialized as base64 in Wagmi (Nethereum works without a problem) when i call write contract with bytes args.

([Web3Modal] Error executing call AbiEncodingBytesSizeMismatchError: Size of bytes "aXRlbXMAAAA=" (bytes12) does not match expected size (bytes8).)

using Nethereum.Hex.HexConvertors.Extensions;

const string contractAddress = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984";
const string recipientAddress = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
const string abi = "...";  // ABI of the ERC20 token contract

BigInteger amount = 1;
string section = "0x6361726473000000"; // bytes8

var arguments = new object[]
{
    recipientAddress,
    amount,
    section.HexToByteArray() // put to array byte, which is required, in documenation actually is missing sample with bytes arg..
};

var result = await Web3Modal.Evm.WriteContractAsync(contractAddress, abi, "transfer", arguments);

To Reproduce Just add any bytes to arguments for contract write and make build for WebGL

Expected behavior result should be 6361726473000000 but i'm getting base64 output is aXRlbXMAAAA= ([Web3Modal] Error executing call AbiEncodingBytesSizeMismatchError: Size of bytes "aXRlbXMAAAA=" (bytes12) does not match expected size (bytes8).)

due "using JsonConvert.SerializeObject from the Newtonsoft.Json library, the byte array will be converted into a Base64-encoded string." ??

Screenshots Here you can see what happend with bytes8 argument, it's now aXRlbXMAAAA=

Screenshot 2024-07-16 014629

Environment

  • OS: Windows 11 (but doesn't matter)
  • Unity version: 6000.0.10f1 (but doesn't matter)
  • Web3Modal Package Version: 0.4.0 · July 08, 202

Is this happening in Unity Editor or on a player like Android, iOS, Windows? WebGL/Wagmi

Wallets used for testing any wallet

Additional context btw on the screenshot is wagmi version 5.0.6 i just replaced for tests (doesnt matter if it's 5.0.1 - current), but after i found that problem is probably inside com.walletconnect.web3modal/Runtime/WebGL/InteropService.cs (but i'm not sure)

snippet of my ABI arg:

{
	""internalType"": ""bytes8"",
	""name"": ""section"",
	""type"": ""bytes8""
},

thirdheronet avatar Jul 15 '24 23:07 thirdheronet