+var updateStatus = status => { // Error handling
+ document.getElementById("status").innerHTML = status;
+function createTokenTransaction() {
+ updateStatus("Getting user address...");
+ web3.eth.getAccounts( (err, acc) => { //get users address
+ updateStatus("error:" + err );
+ updateStatus("creating transaction...");
+ //create sendtransaction using indiesqaure REST api
+ var usersAddress = acc[0];
+ var receivingAddress = "0xf...."; // Ethereum Wallet Address for receiving payment
+ var tokenContractAddress = "0xe....."; // ERC20 Token Contact Address;
+ var amount = 1; // Number of Token to for this payment
+ var http = new XMLHttpRequest();
+ var url = "https://api.indiesquare.me/eth/v1/transactions/send"; // api
+ "to": receivingAddress,
+ "token": tokenContractAddress,
+ http.open("POST", url, true);
+ http.setRequestHeader("Content-type", "application/json");
+ http.onreadystatechange = function() {
+ if (http.readyState == 4 && http.status == 200) {
+ updateStatus("signing transaction...");
+ var unsignedTransaction = JSON.parse(http.responseText);
+ //sign and send the transaction
+ web3.eth.sendTransaction(unsignedTransaction, (err, result) => {
+ if (err != undefined) {
+ updateStatus("sign error:" + err);
+ updateStatus("broadcast transaction...");
+ console.log("https://etherscan.io/tx/"+ result);
+ updateStatus("error creating transaction:" + http.statusText+ " "+http.responseText);
+ http.send(JSON.stringify(params));
+ // no web3 (no wallet in browser or not in dApp browser)
+ alert(e); //web3 not found