For some reason, I can’t seem to call a basic contract with the TypeScript SDK. I’ve tried to deploy the compiled counter contract, but after I deploy it, a simple call to increment the counter fails with the following error:
RevertError: The script reverted with reason Unknown
at revertErrorFactory
...
cause: ScriptResultDecoderError: Execution of the script associated with contract resulted in a non-zero exit code: 1.
Here’s my TypeScript code. I am currently using v0.69 of fuels and v0.46.1 of forc.
import { readFileSync } from 'fs';
import { BN, Contract, ContractFactory, Provider, Wallet } from 'fuels';
async function main() {
const PRIVATE_KEY = '0x...';
const provider = await Provider.create('https://beta-4.fuel.network/graphql');
const byteCode = readFileSync('./out/debug/counter-contract.bin');
const abi = JSON.parse(readFileSync('./out/debug/counter-contract-abi.json', 'utf8'));
const wallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider);
console.log(`Wallet address is: ${wallet.address}`);
let balance = await wallet.getBalance('0x0000000000000000000000000000000000000000000000000000000000000000');
console.log(`The balance of ${wallet.address} is ${balance}`);
const factory = new ContractFactory(byteCode, abi, wallet);
const contract = await factory.deployContract({ gasPrice: 1, gasLimit: 1000000 });
console.log(`Contract deployed by ${wallet.address} address: ${contract.id}`);
const newContract = new Contract(contract.id, abi, wallet);
await newContract.functions
.increment()
.txParams({ gasPrice: new BN(5), gasLimit: new BN(10000000) })
.call();
let value = newContract.functions.count().call();
console.log(`The value is ${value}`);
}
main();
Hello, @wilhelm.potts.
I am sorry about this issue.
To better understand what is happening, can you answer one thing for us?
I can see that your code handles 2 contract calls. Do you happen to know which of the contract calls is throwing this error? The first one or the second one? Adding a log between them should be enough to validate this.
Also, on the second contract call, we need to inform the txParams as well.
Hmm… Actually, I’m now getting an entirely different error. It’s now saying that I don’t have coins in my wallet to deploy the contract (but the block explorer says I have a balance of 2)…
Here’s my entire script (with my test private key). Please try running it:
import { readFileSync } from 'fs';
import { BN, Contract, ContractFactory, Provider, Wallet } from 'fuels';
async function main() {
const PRIVATE_KEY = '0xbaa045c573957317f0d981ced11f9f2b019137219861dcfc975bf219f9d43034';
const provider = await Provider.create('https://beta-4.fuel.network/graphql');
const byteCode = readFileSync('./out/debug/counter-contract.bin');
const abi = JSON.parse(readFileSync('./out/debug/counter-contract-abi.json', 'utf8'));
const wallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider);
console.log(`Wallet address is: ${wallet.address}`);
let balance = await wallet.getBalance('0x0000000000000000000000000000000000000000000000000000000000000000');
console.log(`The balance of ${wallet.address} is ${balance}`);
const factory = new ContractFactory(byteCode, abi, wallet);
const contract = await factory.deployContract({ gasPrice: 1, gasLimit: 1000000 });
console.log(`Contract deployed by ${wallet.address} address: ${contract.id}`);
const newContract = new Contract(contract.id, abi, wallet);
await newContract.functions
.increment()
.txParams({ gasPrice: new BN(5), gasLimit: new BN(10000000) })
.call();
console.log('INCREMENT CALLED...');
let value = await newContract.functions.count().call();
console.log(`The value is ${value}`);
}
main();