The OMG transaction is listed here on etherscan. I initiated it around 7:30 AM this morning, even though the timestamp on that page always seems to restart everytime I refresh the page. I found a myetherwallet.com help page for cancelling a pending transaction. The instructions for cancelling a transaction involve generating a '0 ETH' transaction to your own address, along with other details. My question is, should I still be doing a 0 ETH transaction to myself, or a 0 OMG transaction to myself since the original transaction was OMG and not ETH?
[Ethereum] “cancel” a token transfer transaction by sending ether
erc-20myetherwallettokens
Related Solutions
You can manually encode data with the function:
public static String encodeTransferData(String toAddress, BigInteger sum) {
Function function = new Function(
"transfer", // function we're calling
Arrays.asList(new Address(toAddress), new Uint256(sum)), // Parameters to pass as Solidity Types
Arrays.asList(new org.web3j.abi.TypeReference<Bool>() {}));
return FunctionEncoder.encode(function);
}
and call the contract this way:
public static void main(String[] args) throws Exception {
Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/
Credentials creds = WalletUtils.loadCredentials("password", "path/to/wallet");
RawTransactionManager manager = new RawTransactionManager(web3, creds);
String toAddress = "0x..."; // destination address
String contractAddress = "0x...";
BigInteger sum = BigInteger.valueOf(10000); // amount you want to send
String data = encodeTransferData(toAddress, sum);
BigInteger gasPrice = web3.ethGasPrice().send().getGasPrice();
BigInteger gasLimit = BigInteger.valueOf(120000); // set gas limit here
EthSendTransaction transaction = manager.sendTransaction(gasPrice, gasLimit, contractAddress, data, null);
}
I can't see what's wrong with the token contract.
Concerning the second one, you should do :
function sendTokens () public payable returns (uint)
{
AppleToken appleToken = AppleToken(tokenAddress);
require(appleToken.transfer(msg.sender, 10));
return appleToken.balanceOf(msg.sender);
}
- No need to declare the appleToken variable then set it, you can combine both.
- Be sure that
tokenAddress
is the correct one. - Always use a
require
when doing token transfer! Do not think it works like thetransfer
method forether
, which handles failure and will throw for you.
EDIT :
I have tested the contracts and it works fine. I think you simply forgot to send tokens to the EquityInvestments
contract, hence token balance of msg.sender
staying at 0
.
Best Answer
A 0 ETH transaction with the same nonce as the transaction to be cancelled is fine. The same account cannot have two transactions with the same nonce; any transaction (with high enough gas price), really, could be used to replace the one that's still pending.