I am making a call to the Dai contract on the Kovan testnet to facilitate transactions between any two addresses entered as input. I was able to successfully make read calls but I realized I needed to sign transcations using a key for every write call. How do I do this using web3? I have my code below for clarity :
const Web3 = require("web3");
const axios = require('axios');
const WebSocket = require('ws');
const Web3Utils = require('web3-utils');
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.WebsocketProvider("wss://kovan.infura.io/ws/v3/d28ff5674c0848ada11af62d25c6a2f1"));
}
web3.eth.defaultChain = 'kovan';
var DaiContract = new web3.eth.Contract('ABI-HERE','0xC4375B7De8af5a38a93548eb8453a498222C4fF2');
$("#button").click(function() {
DaiContract.methods.transferFrom($("#address1").val(), $("#address2").val(), $("#amount").val()).call()
.then(function(result){
$("#result").html("Successfully transferred " + $("amount").val() + " Dai.");
DaiContract.methods.balanceOf($("#address1").val()).call()
.then(function(result){
console.log('Remaining balance in address1 : ' + value);
})
.catch(function(error){
console.error('Error : ' + error);
});
})
.catch(function(error){
console.error('Error : ' + error);
$("#result").html("Transfer failed");
});
});
Gives the following error :