Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
987 B
1
Indexable
Never
app.post("/transaction", async (req, res) => {
  let toAddress = req.body.to_address || "";
  let amount = req.body.amount || 0;

  contract.methods.decimals().call() = 9

  let data = await contract.methods.transfer(toAddress, amount * 10^9).encodeABI();
  let txObj = {
    gas: process.env.GAS,
    gasPrice: web3.utils.toWei(process.env.GAS_PRICE_GWEI, "gwei"),
    to: process.env.CONTRACT_ADDRESS,
    value: "0x00",
    data: data,
  };
  web3.eth.accounts.signTransaction(
    txObj,
    "0x" + process.env.PRIVATE_KEY,
    (err, signedTx) => {
      if (err) {
        return callback(err);
      } else {
        console.log(signedTx);
        return web3.eth.sendSignedTransaction(
          signedTx.rawTransaction,
          (err, res) => {
            if (err) {
              console.log(err);
            } else {
              console.log(res);
            }
          }
        );
      }
    }
  );
  res.send({ status: true });
});