code is:
const deployContract = async () => {
const contractWasm = contract_file.source.wasm;
const contract = new ContractPromise(api,abi,contractWasm);
const initValue = true;
console.log("contract is :", contract);
const tx = await contract.tx.new({ gasLimit, storageDepositLimit }, initValue)
setContractAddress(contract.address.toString());
}
error is:
Unhandled Runtime Error
TypeError: contract.tx.new is not a function
I'm sorry. It was a simple mistake. It was just that the correct answer was to use "CodePromise" instead of "ContractPromise".
Fixed code:
const deployContract = async () => {
const { web3FromSource } = await import("@polkadot/extension-dapp");
const contractWasm = contract_file.source.wasm;
const contract = new CodePromise(api, abi, contractWasm);
const initValue = true;
console.log("contract is :", contract);
const performingAccount = accounts[0];
const injector = await web3FromSource(performingAccount.meta.source);
const tx = contract.tx.new({ gasLimit, storageDepositLimit }, initValue);
let address = "";
const unsub = await tx.signAndSend(
actingAddress,
{ signer: injector.signer },
({ contract, status }) => {
if (status.isInBlock) {
setResult("in a block");
} else if (status.isFinalized) {
setResult("finalized");
address = contract.address.toString();
setContractAddress(address);
unsub();
}
}
);
};