Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Samboy76 opened this issue Jun 6, 2023 · 2 comments

Comments

@Samboy76
Copy link

Samboy76 commented Jun 6, 2023

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!

@hydai
Copy link
Member

hydai commented Jun 6, 2023

SOLL follows the standard of EWASM. It will not export any public function defined by users to the export list. Instead, please use the EVM way to interact with the generated contracts.

@Samboy76
Copy link
Author

Samboy76 commented Jun 7, 2023

Thanks for the reply. So I gather it’s nothing wrong with the SOLL compilation to the binary object then? Is there an -debug option to soll command line that would spit out any possible compilation errors? Can you kindly adjust the above JavaScript code snippet to work in EVM way as I’m a newbie in this space and have already spent several days on it trying to get this to work effectively. Thanks again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants