Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I'm writing a shopify function to apply discounts to the cart items. I wanted to verify the caller and the contents of the cart in the function. The caller sends additional data in the cart attributes signed using a private key and I want to verify the signature using public key inside the function. I'm implementing this in typescript and Shopify's Javy runtime doesn't allow usage of modules like crypto. The javascript libraries that can do this increase the function.wasm file's size to more than the allowed 256KB limit.
This appears specifically a restriction due to the language I chose to write the function. If I implement the function in Go, I can take advantage of the libraries and I can compile that to a .wasm as well using tinygo. https://shopify.dev/docs/apps/build/functions/programming-languages/webassembly-for-functions tells that is possible. What I don't understand is how to deploy the custom .wasm file I have as the actual Shopify function. Shopify CLI takes care of deploying the extension behind the scenes. If I have my custom .wasm file, how do I make Shopify understand that this is what I want to deploy as the function ?
Solved! Go to the solution
This is an accepted solution.
Hi @sriram-1 --
I'm surprised you hit the binary size limit in JavaScript -- but regardless, JavaScript will definitely hit the instruction count limit if you try to do any crypto operations.
Rust would be the more supported option, but you can find an old example of using Golang here. I had to use TinyGo w/ leaking garbage collection at the time, and definitely needed wasm-opt to get things within the binary limit.
https://github.com/nickwesselman/polyglot-functions/tree/main/app/extensions/order-discount-golang
You can use the 'Wasm' template option when creating a function extension, and then fill in the [build] section of shopify.extension.toml with the build command, binary path, and (optionally) the file watch path(s).
Some relevant documentation:
https://shopify.dev/docs/apps/build/functions/programming-languages/webassembly-for-functions
https://shopify.dev/docs/api/functions/configuration#properties
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
Hi @sriram-1 --
I'm surprised you hit the binary size limit in JavaScript -- but regardless, JavaScript will definitely hit the instruction count limit if you try to do any crypto operations.
Rust would be the more supported option, but you can find an old example of using Golang here. I had to use TinyGo w/ leaking garbage collection at the time, and definitely needed wasm-opt to get things within the binary limit.
https://github.com/nickwesselman/polyglot-functions/tree/main/app/extensions/order-discount-golang
You can use the 'Wasm' template option when creating a function extension, and then fill in the [build] section of shopify.extension.toml with the build command, binary path, and (optionally) the file watch path(s).
Some relevant documentation:
https://shopify.dev/docs/apps/build/functions/programming-languages/webassembly-for-functions
https://shopify.dev/docs/api/functions/configuration#properties
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog