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 
    at GethApiDouble.eth_sendTransaction 
    at GethApiDouble.handleRequest (/usr/local/lib/node_modules/ethereumjs-
    at next (/usr/local/lib/node_modules/ethereumjs-
    at VmSubprovider.handleRequest (/usr/local/lib/node_modules/ethereumjs-
    at next (/usr/local/lib/node_modules/ethereumjs-
    at GethDefaults.handleRequest (/usr/local/lib/node_modules/ethereumjs-
    at next (/usr/local/lib/node_modules/ethereumjs-
    at FilterSubprovider.handleRequest 
    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.


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});
  • 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.