How can I make this async function run in Bubble?

Hi,

I have this piece of code working in nodeJS but when I try to run it in the plugin editor it does nothing and the console says it’s waiting for a promise.

I read about adding context.async but when I do that the plugin editor says it is invalid javascript. Can anyone help me format this correctly for Bubble to return the promise and execute the function, please?

const createDirectListing = async () => {
  // The contract address of the NFT that will be auctioned
  const nftCollectionAddress = "<collectionaddress>";

  await marketplace.createDirectListing({
      
      assetContractAddress: nftCollectionAddress,
      buyoutPricePerToken: ethers.utils.parseUnits("1000"),
      currencyContractAddress: "0xeb8f08a975Ab53E34D8a0330E0D34de942C95926",
      listingDurationInSeconds: 60 * 60 * 24,
      quantity: 1,
      startTimeInSeconds: Math.floor(Date.now() / 1000),
      tokenId: 0,
    })
    .then((data) => console.log(data))
    .catch((error) => console.error(error));
};

Thank you any help is much appreciated!
Jack

1 Like

I’m using the following solution:

2 Likes

Why not context.async ?

the last time I checked, I don’t think async-await syntax is supported in the plugin editor yet. You have to use the legacy .catch syntax.

(i know, pain in the ***)

Thank you I will give this a go!

Bubble says it invalid JavaScript for some reason, I’ve seen it work in other places though, Weird hahaha

Okay awesome I’ll give this a go, thank you!

let me know how it goes :slight_smile:

Something in the form of:

assuming the “marketplace” variable is pre-defined, and that “< collectionaddress >” is just a placeholder for the actual fetch link that you don’t want to expose.

edit: resp.json should be resp.json()

You may have to JSON.Stringify() or .String() stuff and format things back and forth from JSON.

Here’s a helpful link that does this process in reverse: Refactoring Promise Chains w/Async-Await | by Brian Lego | JavaScript in Plain English

cheers
@JackMorgan.xyz

1 Like