Hello,
I am using following code with node api to invoke contract
import { ConcordiumGRPCWebClient, ContractContext ,AccountAddress, ContractAddress, Parameter, ReceiveName, Energy, CcdAmount } from ‘@concordium/web-sdk’;
const client = new ConcordiumGRPCWebClient(
‘https://node.testnet.concordium.com’,
20000
);
export async function invokeSmartContract(contractAddress: number, entrypoint: string, parameter: any) {
const invoker = AccountAddress.fromBase58(‘3SfHLNkmy61ZUQkAhMvAwKj47EYDBiUPbn3wHghFD6qGr8WDGc’);
const contract = ContractAddress.create(contractAddress);
const receiveName = ReceiveName.fromString(entrypoint);
const param = Parameter.fromHexString(parameter);
const energy = Energy.create(30000);
const amount = CcdAmount.fromCcd(0)
const context: ContractContext = {
// Required
method: receiveName,
contract,
// Optional
invoker,
amount,
parameter,
energy,
};
const result = await client.invokeContract(context);
return result;
}
I am getting following error
/home/yasir/concordium_dev/dapps/NodeApi/node_modules/ts-node/dist/index.js:851
return old(m, filename);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/yasir/concordium_dev/dapps/NodeApi/node_modules/@concordium/web-sdk/lib/esm/index.js from /home/yasir/concordium_dev/dapps/NodeApi/src/concordiumService.ts not supported.
Instead change the require of index.js in /home/yasir/concordium_dev/dapps/NodeApi/src/concordiumService.ts to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (/home/yasir/concordium_dev/dapps/NodeApi/node_modules/ts-node/dist/index.js:851:20)
at Object. (/home/yasir/concordium_dev/dapps/NodeApi/src/concordiumService.ts:13:19)
at m._compile (/home/yasir/concordium_dev/dapps/NodeApi/node_modules/ts-node/dist/index.js:857:29) {
code: ‘ERR_REQUIRE_ESM’
}