current position:Home>How to use private key offline signature to initiate a contract call transaction?

How to use private key offline signature to initiate a contract call transaction?

2022-02-03 20:51:27 Q & A of Denglian community

I am using web3 Prepare to develop a background program to automatically call some contracts regularly , web3.js My documents don't understand , Can you write an example code , thank you .




Take the answer 1:
//  Construct a contract call transaction var contract = new web3.eth.Contract(contractJson, contractAddress);var transfer = contract.methods.transfer("0x...", 490);var encodedABI = transfer.encodeABI();var tx = {    from: "0x...",    to: contractAddress,    gas: 2000000,    data: encodedABI  };  //  Sign the deal web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {    var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);    tran.on('confirmation', (confirmationNumber, receipt) => {      console.log('confirmation: ' + confirmationNumber);    });    tran.on('transactionHash', hash => {      console.log('hash');      console.log(hash);    });    tran.on('receipt', receipt => {      console.log('reciept');      console.log(receipt);    });    tran.on('error', console.error);  });



copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032051249605.html

Random recommended