1

Here is my scenario . We have wallets (accounts) with private keys . In case of raw transaction I know how I can use private keys for signing tx . How I can use private key for an account when I am calling smart contract methods ? Thanks

  • You want to use the private keys of these wallets in the smart contract? – Eli Drion Apr 2 '18 at 7:25
  • Yes , I understand in order to interact with wallets you need to use private keys , but in smart contract I don't see a way – Hrach Karapetyan Apr 2 '18 at 7:45
  • You don't need the private keys to "interact" with wallets. What do you want to do? Send ETH or tokens? – Eli Drion Apr 2 '18 at 7:46
  • yes sending tokens – Hrach Karapetyan Apr 2 '18 at 8:00
  • You don't need the private key for sending tokens. – Eli Drion Apr 2 '18 at 8:06
-1

Here are three functions I use a lot to interact with a smart contract and a signed transaction:

function sendTransaction(tx) {
    return new Promise((resolve, reject) => {
        web3g.eth.sendSignedTransaction(tx.rawTransaction)
            .on('transactionHash', function (hash) {
                resolve(hash);
            });
    });
}
// tx = the transaction object from "generateTx"
function signTransaction(tx, private_key) {
    return new Promise((resolve, reject) => {
        web3g.eth.accounts.signTransaction(tx, private_key)
            .then(function (signed_tx) {
                resolve(signed_tx);
            }).catch(function (error) {
                console.log(error);
                reject("request failed");
            });
    });
}

// instance = contract instance
// body = some parameters
function generateTx(body, instance) {
    return new Promise((resolve, reject) => {
        try {
            let encoded_tx_data = instance.methods.transfer(body.destinationAddress, body.transferAmount).encodeABI();
            let tx_object = {
                gas: 2000000,
                data: encoded_tx_data,
                from: body.senderAddress,
                to: body.contractAddress
            };
            resolve(tx_object);
        } catch (error) {
            console.log(error);
            reject("request failed");
        }
    });
}
  • but those are jsut methods to interact with web3 right ? you don't have this methods in smart contract ?? – Hrach Karapetyan Apr 2 '18 at 12:00
  • No you don't. Priate keys have nothing to do ith smart contract itself – Florian Castelain Apr 2 '18 at 13:39
  • in that key s if you have bunch of wallets and private keys , how do you make transactiopns using sm contract methods – Hrach Karapetyan Apr 2 '18 at 15:27
  • yes for instance to send tokens using web3 – Hrach Karapetyan May 15 '18 at 9:52

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.