TransWikia.com

What is the corresponding web3 type to solidity bytes when using Typescript?

Ethereum Asked by Suzana Maranhão Moreno on December 13, 2021

I want to call a solidity function a passing a parameter bytes b.

function xyz(address a, bytes hexData)

We front end code in Typescript is like that

if (hexData) {

    let hexDataInBytes = Web3Utils.hexToBytes(hexData);
    console.log("hexDataInBytes "); 
    console.log(hexDataInBytes); 

    this.getAccounts().then(accounts => {
            let selectedAccount = accounts[0];
            let contract =  this.createContract(addr);

            contract.instance.methods.xyz(toAddress, hexDataInBytes)
            .send ({ from:selectedAccount, gas:500000 })
            .then (result => fSucess(result))
            .catch (error => fError(error));
        }); 

}

Passing hexData = 0x0123, I got hexDataInBytes = [1,35].
However, I got the error

RROR Error: Uncaught (in promise): Error: Given parameter is not bytes: “1,35”
Error: Given parameter is not bytes: “1,35”
at SolidityTypeDynamicBytes.formatInputDynamicBytes [as _inputFormatter] (formatters.js:83)
at SolidityTypeDynamicBytes.SolidityType.encode (type.js:188)
at eval (index.js:255)

So, what is the correct way to call this function xyz?

Thank you!

One Answer

Just send the hex string and it should work.

contract.instance.methods.xyz(toAddress, 0x0123)

Answered by Micky Socaci on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP