How to generate ScriptSum

Hello, I want to generate ScriptSum to perform similar transaction as this. I have checked all your documention but couldn’t find a command on how to do this

import { ScriptTransactionRequest, Provider, Wallet } from 'fuels';
import { ScriptSum } from '../../../../typegend'; // Replace with your contract/script

const provider = new Provider(LOCAL_NETWORK_URL);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);

// Instantiate the transaction request using a ScriptTransactionRequest
const scriptTransactionRequest = new ScriptTransactionRequest({
  script: ScriptSum.bytecode, // Use your contract's bytecode
});

// Set the script main function arguments (e.g., incrementing the counter)
const incrementAmount = 1; // Amount to increment
scriptTransactionRequest.setData(ScriptSum.abi, [incrementAmount]);

// Optionally, add any coin outputs if needed
const baseAssetId = await provider.getBaseAssetId();
scriptTransactionRequest.addCoinOutput(wallet.address, 1000, baseAssetId);

// Estimate and fund the transaction
await scriptTransactionRequest.estimateAndFund(wallet);

// Send the transaction
await wallet.sendTransaction(scriptTransactionRequest);

Hey @JayWebtech, help me understand, are you looking to create script txn using the ts SDK? or are you looking for something else?

Hello @naz3eh Thanks for reaching out

Yes, I have a counter counter and I want to create a script txn but I don’t know if it is possible to interact with my counter contract using ScriptTransactionRequest

I used const call = await contract.functions.decrement_counter(1).call(); and it works fine but I need a use case using ScriptTransactionRequest

You can create custom script txns using ScriptTransactionRequest, for contracts you can have a look at here

Thank you so much. It now works

1 Like