sCrypt-Inc / scryptlib

Javascript SDK
MIT License
46 stars 28 forks source link

Unable to import class extending SmartContract using ESM #258

Closed AwesomeKalin closed 6 months ago

AwesomeKalin commented 6 months ago

I am developing a project that uses ESM imports. When I started to integrate my first sCryt SmartContract, I used esm syntax in it too, so that it would play nice with tsc, however it was giving the following error:

Unable to resolve signature of property decorator when called as an expression.
  Argument of type 'ClassFieldDecoratorContext<ProceduralSaving, ByteString> & { name: "manifest"; private: false; static: false; }' is not assignable to parameter of type 'string'.

So, I moved this file out of the main src directory and into a contracts file and used the scrypt ts-config to allow it to still be compiled and then used the artifact generated to import into the rest of the code. I got the code to deploy just fine, however when calling the contract, it no longer allows me to connect a wallet, even the basic test wallet, meaning that I cannot make signatures to call my functions. Here is the code: https://github.com/AwesomeKalin/BSV-Utils. Any help is appreciated!

AwesomeKalin commented 6 months ago

I figured it out!

  1. Copy everything from the contract into a .js file
  2. Remove types and @prop and @method
  3. Create a .d.ts file for IntelliSense
  4. Copy into your build directory