0
<script src="{{ asset('web3.js-1.0.0-beta.34/dist/web3.min.js') }}"></script>



<script type="text/javascript">

var web3 = new Web3(new Web3.providers.HttpProvider('http://58.242.352.4:8545'));

console.log('web3 version:'+ web3.version);

// ShahzadTestCoin contract ABI Array
var abiArray =[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"fundsWallet","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"unitsOneEthCanBuy","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalEthInWei","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"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"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"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"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}];

// Who holds the token now?
var myAddress = "0x429c4474c5914a28063e2c37ca23bb4af9ef0728";
// Who are we trying to send this token to?
var destAddress = "{{$etherAddress}}";
// ShahzadTestCoin Token (STC)
var transferAmount = 1;
// Determine the nonce
var count;


// The address of the contract
var contractAddress = "0xc61BEC3497e549b9fA58AE79a5a573E064fe3311";
var myContract = new web3.eth.Contract(abiArray, contractAddress);
myContract.options.from = myAddress;
var privateKey = '4dc63fa369264ebe211ba70xxxxxxxx....';

web3.eth.getTransactionCount(myAddress, function(err, count){

        if(!err){

            count = count;
            web3.eth.getBalance(myAddress , function(err, res){

                //console.log("getBalance ShahzadTestCoin: "+res);

                console.log('Balance before send:' +res);
                    count = res;

                    // Chain ID of Ropsten Test Net is 3, replace it to 1 for Main Net
                    var chainId = 3;
                    var transactionObject = {
                        "from": myAddress,
                        "gas": "0x5208",
                        "gasPrice": '0x4A817C800',
                        "to": contractAddress,
                        "value": "0",
                        "data": contract.methods.transfer(destAddress, transferAmount).encodeABI(),
                        "chainId": chainId
                    };


                     web3.eth.accounts.signTransaction(transactionObject, privateKey, function(err, signed){

                        //console.log("signTransaction err: "+err);
                        console.log("signTransaction signed: "+signed.rawTransaction);

                        web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, res){
                            console.log("sendSignedTransaction  err: "+err);
                            console.log("sendSignedTransaction  res: "+res);
                        });


                    });




            });    



        }//if(!err){
});

</script>

Any idea what am I doing wrong here?

1

I'm using "web3": "^1.0.0-beta.35" and encountered this problem as well. I only changed the gasPrice to a number instead of hex value. I'm not sure if it will solve your problem with the beta.34 version but try and change the gasPrice and gas to just numbers and see if it works. Example: gasPrice: 10000000000

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.