multiversx / mx-sdk-js-core

MultiversX SDK for interacting with the MultiversX blockchain (in general) and Smart Contracts (in particular).
https://multiversx.github.io/mx-sdk-js-core/
Other
60 stars 37 forks source link

NativeSerializer cannot parse enum value #216

Closed gfusee closed 1 year ago

gfusee commented 2 years ago

Hi,

It seems convertToTypedValue method from NativeSerializer cannot handle enum, the workaround is to not currently use ABI to call endpoints that require enum

I'm using erdjs 10.2.4

Thank you

TheoSabattie commented 2 years ago

Workaround:

axios.get('your.abi.json').then((response) => {
    const networkProvider = new ProxyNetworkProvider(
        'https://devnet-gateway.elrond.com' // or the main/test net
    );

    const abiRegistry = AbiRegistry.create(response.data);
    const abi = new SmartContractAbi(abiRegistry);
    const contract = new SmartContract({
        address: new Address(yourConfig.contractAddress),
        abi: abi
    });

    // here
    const gameStateType = abiRegistry.getEnum('GameState');

    const interaction = contract.methodsExplicit.stateToGames([
      EnumValue.fromName(gameStateType, "WaitingPlayer")
    ]);

    const query = interaction.buildQuery();
    networkProvider.queryContract(query).then((queryResponse) => {
        const endpointDefinition = interaction.getEndpoint();
        const resultsParser = new ResultsParser();

        const { firstValue, secondValue, returnCode } =
            resultsParser.parseQueryResponse(queryResponse, endpointDefinition);
    });
});
andreibancioiu commented 1 year ago

Fixed in https://github.com/multiversx/mx-sdk-js-core/releases/tag/v12.6.0.