1
  • I implemented the sample code according to the polkadot.js official site in the link below.

  • Running and testing with "yarn dev" command works as expected.

  • But when I run "yarn build" I get compilation errors.

  • Anyone know how to solve this?

  • Environment

    • next.js
    • polkadot.js 9.5.1, 8.13.1, 8.4.1 #tried multiple versions

Sample Code:

const deployContract = async () => {
    const { web3FromSource } = await import("@polkadot/extension-dapp");
    const keyring = new Keyring({ type: 'sr25519' });
    const alicePair = keyring.addFromUri('//Alice', { name: 'Alice default' });
    const caller = keyring.addFromAddress("actingAddress");
    const wsProvider = new WsProvider(blockchainUrl);
    const api = await ApiPromise.create({ provider: wsProvider });
    setApi(api);
    const contractWasm = contract_file.source.wasm;
    const code = new CodePromise(api, abi, contractWasm);
    const initValue = false;
    console.log("contract is :", code);
    const performingAccount = accounts[0];
    const injector = await web3FromSource(performingAccount.meta.source);
    const tx = code.tx.new({ gasLimit, storageDepositLimit }, initValue)
    let address;
    const unsub = await tx.signAndSend(alicePair, ({ contract, status }) => {
      if (status.isInBlock || status.isFinalized) {
        address = contract.address.toString();
        unsub();
      }
    });
  };

Compile Error:

./pages/index.tsx:64:10
Type error: Property 'contract' does not exist on type 'ISubmittableResult'.

  62 |       actingAddress,
  63 |       { signer: injector.signer },
> 64 |       ({ contract, status }) => {
     |          ^
  65 |         if (status.isInBlock) {
  66 |           setResult("in a block");
  67 |         } else if (status.isFinalized) {

> Build error occurred

Thank you.

s.Takahashi
  • 469
  • 4
  • 15

0 Answers0