decentraland / decentraland-eth

DEPRECATED - Ethereum common helpers for Decentraland
https://decentraland.github.io/decentraland-eth/
Apache License 2.0
15 stars 9 forks source link

Issue with executeOrder method #80

Closed xenoliss closed 4 years ago

xenoliss commented 4 years ago

Hi,

I'm trying to learn web3js and all that stuff about ethereum blockchain by developing a frontend client to interact with decantraland contracts but I'm struggling when I want to buy a nft from my javascript.

I'm using the function below to buy a nft:

async function buy(nftAddress, assetId, priceInWei, estimatedGas, gasPrice) {
    marketPlaceContract.methods
        .executeOrder(
            nftAddress,
            assetId,
            priceInWei,
        )
        .send({
            from: process.env.ETH_PUBLIC_KEY,
            gasPrice: gasPrice.toString(), 
            gas: estimatedGas.toString(),
            value: priceInWei.toString(),
        })
        .on('transactionHash', (hash) => {
            console.log("We bought it ! " + hash)
        })
}

But i'm getting this error: Error: Can not send value to non-payable contract method or constructor And indeed, looking at the ABI this is marked as nonpayble... So how should I use this method ?

An other error happens when I try to call estimateGas() on the executeOrder methods of the contract like :

 async function estimateGasToBuy(event) {
    let estimatedGas = await marketPlaceContract.methods
        .executeOrder(
            event.returnValues.nftAddress,
            event.returnValues.assetId,
            event.returnValues.priceInWei,
        )
        .estimateGas({
            from: process.env.ETH_PUBLIC_KEY,
            value: event.returnValues.priceInWei,
        })
}

This call result in Error: Returned error: gas required exceeds allowance (9990231) or always failing transaction.

Could you please help me to get this code working ?

Thanks in advance.