Considering the below code for communicating between web3js and ethereum smart contract in ropsten test net.
web3.eth.getTransactionCount(contractAddress).then(function(lastCountOfTransaction){
var rawTransaction = {
"from": contractAddress,
"nonce": "0x" + lastCountOfTransaction.toString(16),
"gasPrice": web3.utils.toHex(1 * 1e9), //1 can be changed to n gwei
"gasLimit": web3.utils.toHex(1000000), // 1000000 can be to set to any n number
"to": userAddress,
"value": "0x0",
"data": ContractObject.methods.transfer(userAddress, noOfTokens).encodeABI(),
"chainId": chainId
};
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'),function(err,hash){
if (!err){
console.log(hash);
resolve(hash);
}
else{
console.log(err);
resolve(err);
}
});
});
I have multiple token holders like one is contract address which has initial value of tokens and one is token owner which has total number of supply. I want to give tokens from contract address and not from contracts owner account. Token transfer from owner account is working if we change like below
web3.eth.getTransactionCount(myAddress).then(function(lastCountOfTransaction){
var rawTransaction = {
"from": myAddress,
"nonce": "0x" + lastCountOfTransaction.toString(16),
"gasPrice": web3.utils.toHex(1 * 1e9), //1 can be changed to n gwei
"gasLimit": web3.utils.toHex(1000000), // 1000000 can be to set to any n number
"to": contractAddress,
"value": "0x0",
"data": ContractObject.methods.transfer(userAddress, noOfTokens).encodeABI(),
"chainId": chainId
};
But the above code is not working as expected. It do provide me transaction hash but in that tokens are not distributed.
fromaddress? - user94559