Hi, i am trying to call rebase function of my contract using javascript code ,i tried this code to call rebase function in my contract which i deployed on ethereum it works fine,but when i did same process for binance it produce tnx hash has undefined.herewith i am attaching code and screenshot.
const Tx = require('ethereumjs-tx').Transaction
const { Contract } = require('ethers')
const Web3 = require('web3')
const web3 = new Web3('https://bsc-dataseed.binance.org/') //your infura id
const account1 = '0xEB50a80F7DE37AF8669b0C4973B2A33E8502c5a7' // Your account address 1
var contractAddress = "0xFFa3D019C2D46973B42358fC6490608584783034"; //Your implementation address
const abiArray =[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "destination",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
},
{
"indexed": false,
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "TransactionFailed",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "destination",
"type": "address"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "addTransaction",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "eBNBpolicyref",
"outputs": [
{
"internalType": "contract eBNBPolicy",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "eBNBpolicyref_",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "rebase",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "removeTransaction",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
},
{
"internalType": "bool",
"name": "enabled",
"type": "bool"
}
],
"name": "setTransactionEnabled",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "transactions",
"outputs": [
{
"internalType": "bool",
"name": "enabled",
"type": "bool"
},
{
"internalType": "address",
"name": "destination",
"type": "address"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "transactionsSize",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]//abi for contract
const privateKey1 = Buffer.from(process.env.PRIVATE_KEY_1,'hex')
//const privateKey1 = process.env.PRIVATE_KEY_1;
//new Buffer.from(privateKey1.substring(2,66), 'hex')
console.log("Private Key " + privateKey1);
//const privateKey2 = Buffer.from(process.env.PRIVATE_KEY_2,'hex')
const contract = new web3.eth.Contract(abiArray,contractAddress)
const Rebase = contract.methods.rebase().encodeABI()
web3.eth.getBalance(account1 ,(err,bal)=>{console.log(web3.utils.fromWei(bal,"ether"))})//we print the balance of our account
//this function calls by 1 min interval
function rebase(){
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
console.log('Current Timestamp of rebase execution => :', dateTime)
web3.eth.getTransactionCount(account1, (err,txCount) => {
console.log("transaction so far",txCount)
const txObject = {
nonce: web3.utils.toHex(txCount),
to: contractAddress,
gasLimit: web3.utils.toHex(800000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
data :Rebase,
chainId: 56
}
console.log('Step 1 ');
const tx =new Tx(txObject);
//const tx =new Tx(txObject, {chain: 'rinkeby'})
console.log('Step 2 ');
tx.sign(privateKey1)
const serializedTx = tx.serialize()
console.log('Step 3 ');
const raw = '0x' + serializedTx.toString('hex')
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
console.log('txHash:', txHash)
})
console.log('Completed current execution ');
console.log("Tx Hash "+txObject)
})
web3.eth.getBalance(account1 ,(err,bal)=>{console.log(web3.utils.fromWei(bal,"ether"))})//Here we get the balance of our account after rebase
console.log('Step 10 ');
}
setInterval(rebase,60000) //rebase 1min