Skip to content

Problem accessing solidity function from imported wasm binary in Javascript #126

@Samboy76

Description

@Samboy76

Here´s the original solidity source code:

// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// RUN: %soll %s
contract HelloWorld {
   function sayHello() public pure returns (string) {
       return "Hello World";
   }
}

Javascript:

async function loadWasm() {
  const wasmBinary = fs.readFileSync('C:\\Samuel\\Blockchain\\Flashloan-arbitrage-bot-uniswapV2_hardhat_AAVE_flashloan\\artifacts\\helloWorld.wasm');

  const importObject = {
    ethereum: {
      finish: function() {
      }
    }
  };
  
  const instance = await WebAssembly.instantiate(wasmBinary, importObject);
  
  // Call the sayHello() function
  const result = instance.instance.exports.sayHello();
  console.log("Result:", result);
}
loadWasm();

Output:

Exported Functions and Objects: [ 'memory', 'main' ]
module: Module [WebAssembly.Module] {}
instance: [Function: 2]
exports: Module [WebAssembly.Module] {}

C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat_AAVE_flashloan\runarb.js:46
const result = instance.instance.exports.sayHello();
^
TypeError: instance.instance.exports.sayHello is not a function

Would appreciate your help since I have followed the original steps guidance for solidity .sol compilation under README section. FYI there wasn´t any issue in generating the helloWorld.wasm object and can see hexadecimal byte codes inside the file which means the compilation process must have worked ok. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions