Error while trying to broadcast transaction approve in BSC

Hello,

I have an issue with broadcasting transaction approve request in BSC network.

I am trying to use your code sample to run a swap in BSC - Quick start | 1inch Network
However, the issue occurs at broadCastRawTransaction function which is run after buildTxForApproveTradeWithRouter function.

buildTxForApproveTradeWithRouter returns the transaction object:
Debugger attached.
Allowance: 0
Transaction for approve: {
transaction: {
data: ‘0x095ea7b30000000000000000000000001111111254fb6c44bac0bed2854e76f90643097dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff’,
gasPrice: ‘15000000000’,
to: ‘0x111111111117dc0aa78b770fa6a738034120c302’,
value: ‘0’
},
gas: 53000

The object is passed to broadCastRawTransaction and it is used in its fetch request:
let result = await fetch(broadcastApiUrl, {

    method: 'post',
body: JSON.stringify({rawTransaction}),

headers: {'Content-Type': 'application/json'}

})

let json = await result.json();

it returns “Internal Server Error” 500 error message. I am using https://tx-gateway.1inch.io/v1.1/56/broadcast’ as a broadcastApiUrl.

Can you please advise how this can be fixed?

3 Likes

resolved that issue, no need to look into it. thanks.

2 Likes

it’d be great if you should say how you solved it because I’m facing the same issue :confused:

2 Likes

I am having similar issue as well, just with chain id =1. Could you please share what was wrong in your case?

Here is at least one solution:

async function broadCastRawTransaction(rawTransaction) {
let result = await fetch(broadcastApiUrl, {
method: ‘post’,
body: JSON.stringify({ rawTransaction }),
headers: { ‘Content-Type’: ‘application/json’ }
})
let json = await result.json();
let hash = await json.transactionHash;
const status = await waitTransaction(hash);
if (!status) {
console.log(“Approval transaction failed.”);
return;
}
return hash;
}

async function waitTransaction(txHash) {
let tx = null;
while (tx == null) {
tx = await web3.eth.getTransactionReceipt(txHash);
await sleep(2000);
}
console.log(“Transaction " + txHash + " was mined.”);
return (tx.status);
}