1

I deployed an ERC20 contract. I want to send tokens to other addresses without my manual sign.

How can I transfer tokens from my wallet automatically from the server? (via php for example)

Thanks.

1

You can sign a transaction using Node.js web server as this:

const contractAddress = '0x000000'; //Yor token contract address
const privateKey      = '';         //The private key of your contract Owner  
const toAddress       = '0x000000'; //The address to transfer the tokens    

//Creating Web3 Objct
const web3js = new web3(new web3.providers.HttpProvider("https://infura.node.url....."));
    

var contractABI = [];//Contract Token ABI

//creating Contract Object
var contract = new web3js.eth.Contract(contractABI,contractAddress, {from: ownerAddress} ); 

var data = contract.methods.transfer(toAddress, value).encodeABI(); //Create the data for token transaction.

var rawTransaction = {"to": contractAddress, "gas": 100000, "data": data }; 

web3js.eth.accounts.signTransaction(rawTransaction, privateKey)
    .then(signedTx => web3js.eth.sendSignedTransaction(signedTx.rawTransaction))
    //.then(function(receipt){ console.log("Transaction receipt: ", receipt); getETHBalanceOf();  })
    .then(req => { 
            /* The trx was done. Write your acctions here. For example getBalance */
            getTOKENBalanceOf(toAddress).then ( balance => { console.log(toAddress + " Token Balance: " + balance); });
            return true;  
    })      
    

//GET TOKEN BALANCE FUNCTION ////////////////////////////////
async function getTOKENBalanceOf(address){
    return await contract.methods.balanceOf(address).call();                        
}   
1

I am goin to work with NODE.JS as javascript backend webserver. And the NPM ethereumjs-tx module to sign the transactions.

1

You can use a JavaScript library like Web3.js to both sign and make transactions or you can use Web3 to send the transaction you sign with ethereumjs-tx if you prefer.

https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html?highlight=sendTransaction#sendtransaction

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.