spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
336 stars 133 forks source link

Using Lucid in an AWS Lambda function? #207

Open owenbirdsall opened 12 months ago

owenbirdsall commented 12 months ago

I've spent the past few days trying to get Lucid running in my lambda function.

Switching to ESM format and updating to aws-sdk-v3 & nodejs v18 has got me what feels like very close.

However I am now stuck with a Cannot read properties of null (reading 'TransactionBuilderConfigBuilder') error when calling Lucid.new(...

It sounds very similar to https://github.com/spacebudz/lucid/issues/137 ...so I added support for wasm in my CDK NodejsFunction constructor by setting NODE_OPTIONS to "--experimental-wasm-modules" which should add support for loading wasm modules in a lambda environment as described here: https://merckx.dev/notes/loading-wasm.html

However I still get the same error. I then tried multiple versions of Lucid - as recommended by various people who had TransactionBuilderConfigBuilder issues. So far I've tried 0.7.0, 0.7.2, 0.9.8 & 0.10.6, all of which give the same error.

Any help would be greatly appreciated, or if there's an alternative anyone could recommend? My usecase is that I simply want to select a wallet by private key and mint an nft from within a lambda function.

Muhammad-Nabeel-Asif commented 12 months ago

The error message indicates that the property 'TransactionBuilderConfigBuilder' is being accessed on a null object, which means that the object is not properly initialized or defined.

Here are some steps you can follow to debug and fix the issue:

Check if Lucid is properly installed: Ensure that you have installed the Lucid library correctly in your Lambda function. You can check the installation by looking for the 'node_modules' folder in your Lambda deployment package.

Verify the import statement: Double-check the import statement for Lucid in your Lambda function. Make sure you are importing it correctly and using the correct path.

Check for null objects: Review the code that initializes the 'TransactionBuilderConfigBuilder' object. Make sure that it is properly initialized and not set to null at any point before you try to access its properties.

Handle potential null values: If there are cases where 'TransactionBuilderConfigBuilder' might be null, use conditional checks (such as if statements or optional chaining) to handle these scenarios and prevent accessing properties on null objects.

Review the Lucid documentation: Check the official documentation for Lucid to ensure that you are using the library correctly and that you are following the recommended setup and usage instructions.

Enable logging and error handling: Implement logging and error handling in your Lambda function to capture any potential issues during runtime. This will help you identify the specific cause of the error and assist in troubleshooting.

Test in a local environment: Try running your Lambda function in a local development environment (such as on your local machine) with a sample input to see if you can reproduce the error and debug it more effectively.

owenbirdsall commented 12 months ago

Appreciate the help, but I've already tried asking ChatGPT ;)