I have tried all sorts of ways but it's not working for me when i change my value to 0 it works fine the transaction gets submitted.
But if i change it to any other number lets say 1, 10, 20 I get this error.
I have created my owntoken
MyAbi File
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]
MyJavascriptCode
var Tx = require('ethereumjs-tx').Transaction;
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/$[project_key]'));
var amount = web3.utils.toHex(1);
var privateKey = Buffer.from('myprivatekey', 'hex');
var abiArray = JSON.parse(fs.readFileSync('MyAbi.json'));
var contractAddress = '0x37FC4b48CE93'; // ONLYONE address
const amountToSend = 10
console.log("23")
var contract = new web3.eth.Contract(abiArray, contractAddress, {from: fromAddress});
console.log("24")
var count = await web3.eth.getTransactionCount(fromAddress);
// count = '0x' + count.toString(16)
var rawTransaction = {
"gasPrice":web3.utils.toHex(10000000000),
"gasLimit":web3.utils.toHex(8000000),
"to":contractAddress,
"value": 1,
"data":contract.methods.transfer(toAddress, amount).encodeABI(),
"nonce":web3.utils.toHex(count)
};
var transaction = new Tx(rawTransaction, {chain:'ropsten'});
transaction.sign(privateKey)
var result = await web3.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex'), function(err, res){
if(err){
console.log("err-->", err)
}else{
console.log("response--->", res)
}
});
return result;
}
sendOnlyone(fromAdd, '0x11cE'); //fromaddress , toaddress```