I’m callinged contract function to transfer token, and sdk always throw:
Error: Error estimating transaction fee. Response 400: Bad Request. Attempted to fetch https://stacks-node-api.mainnet.stacks.co/v2/fees/transaction and failed with the message: "{"error":"Estimation could not be performed","reason":"NoEstimateAvailable","reason_data":{"message":"No estimate available for the provided payload."}}"
at estimateTransaction (/home/ubuntu/deploy/sbc-buyer/node_modules/@stacks/transactions/dist/builders.js:78:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async makeUnsignedContractCall (/home/ubuntu/deploy/sbc-buyer/node_modules/@stacks/transactions/dist/builders.js:377:23)
at async makeContractCall (/home/ubuntu/deploy/sbc-buyer/node_modules/@stacks/transactions/dist/builders.js:395:29)
at async Function.write (/home/ubuntu/deploy/sbc-buyer/.next/server/chunks/191.js:100:33)
at async Function.withdraw (/home/ubuntu/deploy/sbc-buyer/.next/server/chunks/191.js:142:16)
at async /home/ubuntu/deploy/sbc-buyer/.next/server/chunks/191.js:341:26
at async Proxy._transactionWithCallback (/home/ubuntu/deploy/sbc-buyer/node_modules/@prisma/client/runtime/index.js:40598:18)
at async Function.withdraw (/home/ubuntu/deploy/sbc-buyer/.next/server/chunks/191.js:310:16)
at async handler (/home/ubuntu/deploy/sbc-buyer/.next/server/pages/api/finance/withdraw.js:87:19)
and. here is my code:
async write(fun: string, args: any[]) {
try {
const network = process.env.MAINNET === '1' ? new StacksMainnet() : new StacksTestnet();
const nonce = await prisma.sBCTx.aggregate({
where: {
contractId: process.env.CONTRACT_ID
},
_max: {
nonce: true
}
});
const txOptions = {
contractAddress: process.env.CONTRACT_ADDRESS || '',
contractName: process.env.CONTRACT_NAME || '',
functionName: fun,
functionArgs: args,
senderKey: process.env.PRIVATE_KEY || '',
validateWithAbi: true,
network,
nonce: nonce && nonce._max.nonce ? nonce._max.nonce + 1 : 2,
anchorMode: AnchorMode.Any
};
console.log(txOptions);
const transaction = await makeContractCall(txOptions);
const broadcastResponse = await broadcastTransaction(transaction, network);
return broadcastResponse.txid;
} catch (e: any) {
console.error(e);
sendWarn(e.toString());
return null;
}
}
await this.write('transfer', [
uintCV(toWei(amount)),
standardPrincipalCV(process.env.CONTRACT_ADDRESS || ''),
standardPrincipalCV(address),
optionalCVOf()
]);