reactjsnear

Import WASM file into react app to deploy it on the NEAR Blockchain


I am working on a front end of an app what interacts with the NEAR protocol. The workflow I am creating is:

  1. User signs in
  2. Creates sub account
  3. Deploys a smart contract to the sub account.

Parts 1 and 2 are working fine. for part 3 I have the following code.

//Deploy the contract. 
    let response;
    try {
      response = await subaccount.deployContract(wasamContract);
    }catch(err){
      console.log("Error deploying the contract: ", err)
    }
    console.log("Contract deployed: ", response)

And using the following to import the wasm file:

import wasamContract from "../../assets/main.wasm";

However I get an error on the file import.

./src/assets/main.wasm
Module parse failed: magic header not detected
File was processed with these loaders:
 * ./node_modules/file-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
Error: magic header not detected

So how would I import the wasm file to be used in the above code?


Solution

  • this example should help you, it's an experimental application that deploys smart contracts to any account that registers

    https://github.com/metanear/metanear-web/blob/cea99d6ccd89b733eef3b8d879f86668fa2f7e3c/src/Home.js#L93-L109