Move.

Пост

Поделитесь своими знаниями.

Mister_CocaCola.
Feb 05, 2025
Экспертные Вопросы и Ответы

Struggling to run WebAssembly in TypeScript due to function errors

Hey everyone, I've been trying to load and run WebAssembly from TypeScript but I'm encountering multiple errors about missing functions, like function="__wbindgen_string_new": function import requires a callable. I tried adding __wbindgen_placeholder__: {}, to the imports to fix LinkError: WebAssembly.instantiate(): Import #0 module="__wbindgen_placeholder__" function="__wbindgen_string_new": function import requires a callable, but I'm still facing similar issues. Does anyone have ideas on how to resolve this? Here's my code for reference: async function load_wasm(input: Uint8Array) { const wasmPath = path.resolve(__dirname, 'file.wasm'); const wasmBytes = fs.readFileSync(wasmPath); const memory = new WebAssembly.Memory({ initial: 256, maximum: 512, }); await WebAssembly.instantiate(wasmBytes, { js: { mem: memory }, wbindgen_placeholder: {}, }).then((wasm) => { const helloWasm = wasm.instance.exports.hello_wasm; if (typeof helloWasm === 'function') { const result = helloWasm(input); console.log(result); } else { console.error('hello_wasm is not a function'); } }); }

  • Move CLI
2
1
Поделиться
Комментарии
.

Ответы

1
andreweth..
Feb 5 2025, 11:03

Чтобы понять логику, вы можете ознакомиться с примером в документации Sui: https://docs.sui.io/guides/developer/nft/asset-tokenization#webassembly-wasm-and-template-package.

1
Комментарии
.

Знаете ответ?

Пожалуйста, войдите в систему и поделитесь им.

Move is an executable bytecode language used to implement custom transactions and smart contracts.

148Посты231Ответы
Sui.X.Peera.

Заработай свою долю из 1000 Sui

Зарабатывай очки репутации и получай награды за помощь в развитии сообщества Sui.

Кампания вознагражденийИюль
      Посты с вознаграждением