0

I'm using testrpc -u 0 -u 1 to start the local testnet, deploying my OpenZeppelin Standard Token smart contract with truffle migrate, and using web3 in my dapp.

As the user, I perform an action that calls approve(myContractAddress, amount, {from: myAddress). Then I perform another action that calls transferFrom(myAccount, myContractAddress, amount, {from: myContractAddress}) gives this error:

Error: could not unlock signer account
    at StateManager.queueTransaction 
(/usr/local/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:84996:21)
    at GethApiDouble.eth_sendTransaction 
(/usr/local/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:85804:14)
    at GethApiDouble.handleRequest (/usr/local/lib/node_modules/ethereumjs-
testrpc/build/cli.node.js:85620:10)
    at next (/usr/local/lib/node_modules/ethereumjs-
testrpc/build/cli.node.js:113129:18)
    at VmSubprovider.handleRequest (/usr/local/lib/node_modules/ethereumjs-
testrpc/build/cli.node.js:113829:12)
    at next (/usr/local/lib/node_modules/ethereumjs-
testrpc/build/cli.node.js:113129:18)
    at GethDefaults.handleRequest (/usr/local/lib/node_modules/ethereumjs-
testrpc/build/cli.node.js:85935:12)
    at next (/usr/local/lib/node_modules/ethereumjs-
testrpc/build/cli.node.js:113129:18)
    at FilterSubprovider.handleRequest 
(/usr/local/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:113388:7)
    at next (/usr/local/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:113129:18)

Essentially I want to have the contract transfer my funds to itself, on my behalf. It is almost working except for this error!

This would work: transferFrom(myAccount, someOtherAccount, amount, {from: someOtherAccount}), but I need to be able to send to a contract.

3

Contract accounts cannot be unlocked because they do not have a private key.

You cannot send a transaction on behalf of a contract. It has to be the contract making the call from Solidity. For example:

// In a method of your contract
function makeTransfer(address token, address myAccount, uint256 amount) public {
    ERC20(token).transferFrom(myAccount, address(this), amount);
}

Then you can call it from javascript with:

const tx = await myContract.makeTransfer(myToken.address, myAccount, amount);

Another possibility is to do a normal transfer to your contract address:

const tx = await myToken.transfer(myContractAddress, amount, {from: myAccount});
| improve this answer | |
  • It is better if you ask a new question so it is easier to add your own details. In any case you cannot make a transfer on behalf of a contract. – Ismael May 14 '18 at 16:54

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.