Basic Example
Let's use launchTestNode
with the counter contract from the Fuel dApp tutorial.
Note: you will have to change the import paths of the contract factory and bytecode to match your folder structure.
ts
See code in contextimport { CounterFactory } from '../typegend/contracts/CounterFactory';
using launchedContractNode = await launchTestNode({
contractsConfigs: [{ factory: CounterFactory }],
});
const {
contracts: [contract],
provider,
wallets,
} = launchedContractNode;
const { waitForResult } = await contract.functions.get_count().call();
const response = await waitForResult();
console.assert(response.value.toNumber() === 0, 'Counter is not initialized');
console.assert(provider instanceof Provider, 'Provider is not instance of Provider');
console.assert(wallets.length === 4, 'Wallets length is not 4');
Summary
- The
launched
variable was instantiated with theusing
keyword. launchTestNode
spun up a short-livedfuel-core
node, deployed a contract to it and returned it for testing.- The deployed contract is fully typesafe because of
launchTestNode
's type-level integration withtypegen
outputs. - Besides the contract, you've got the provider and wallets at your disposal.