simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
441 stars 270 forks source link

How to send string to Transaction(data)? #205

Closed athlona64 closed 2 years ago

athlona64 commented 2 years ago

i have data

0x095ea7b300000000000000000000000011111112542d85b3ef69ae05771c2dccff4faa26ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

and type is string

i will send this data to contract

but below is can sent but data is incorrect

    Uint8List bytes = Uint8List.fromList(data.codeUnits);
    final tx = await client.sendTransaction(
        credentials,
        Transaction(
            data: bytes,
            gasPrice: EtherAmount.fromUnitAndValue(EtherUnit.wei, int.parse(gasPrice)),
            to: EthereumAddress.fromHex(to),
            value: EtherAmount.fromUnitAndValue(EtherUnit.wei,  value),
            from: ownAddress,
            nonce: nonce
        ),
        chainId: int.parse(chainId)
    );

expected data is : above

but on chain show so incorrect https://bscscan.com/tx/0x74def6475a25402b3d30afc7ee20f8a51ba5d98af3983be826b7cf020fdab21b

0x307830393565613762333030303030303030303030303030303030303030303030303131313131313132353432643835623365663639616530353737316332646363666634666161323666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
athlona64 commented 2 years ago

hexToBytes('0x095ea7b300000000000000000000000011111112542d85b3ef69ae05771c2dccff4faa26ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');

is not work

athlona64 commented 2 years ago

can solve with remove from parameters

    final tx = await client.sendTransaction(
        credentials,
        Transaction(
            data: hexToBytes(data),
            gasPrice: EtherAmount.fromUnitAndValue(EtherUnit.wei, int.parse(gasPrice)),
            to: EthereumAddress.fromHex(to),
            value: EtherAmount.fromUnitAndValue(EtherUnit.wei,  value),
            nonce: nonce
        ),
        chainId: int.parse(chainId)
    );