0

I am transferring token to the User's wallet when they create account. For that I am using google cloud functions. Here, on the account creation event, tokens will get transferred to the address. My cloud function is working fine but the token transfer function is not getting triggered. Here is the code-

 const admin = require('firebase-admin');
 const functions = require('firebase-functions');
 admin.initializeApp(functions.config().firebase);
 var Web3 = require('web3');
 var web3 = new Web3(new 
 Web3.providers.HttpProvider("http://localhost:8545"));
 var Personal = require('web3-eth-personal')
 var personal = new Personal(Personal.givenProvider)]
 var ABI = [{
     ' contract ABI'
 }]
 var contract = new web3.eth.Contract(ABI, '0xF62E01...571ae957')
 exports.newUser = (event, callback) => {
const triggerResource = event.resource;
web3.eth.personal.unlockAccount("0xc..9050f547", "password", 60, (unlock) => 
 {
         contract.methods.transfer('0x4..bB7d982D8A8632e', 2).
         send({
             from: '0xC3Fe4...0F547',
             gas: 900000
         }, (error, txhash) => {
             if (!error && txhash) {
                 console.log(triggerResource);
             }
              callback();
          });
         })
       };

I have deployed the contract on the private network.

  • 21000 gas is low for token transfers. 21000 is the gas required for ETH transfer. Try increasing gas to 90,000 – Prashant Prabhakar Singh Jan 22 at 11:33
  • 2,300 would be the eth transfer stipend, but this is an ERC20 transfer. Different beast. 20,000 for an SSTORE plus overhead. Agree, it needs more gas. – Rob Hitchens - B9lab Jan 22 at 15:51
  • I increased the gas price to 900,000 but still the transaction is not taking place. – crypto S. Jan 23 at 6:47

Your Answer

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

Browse other questions tagged or ask your own question.