I guess sort of for the first question. If you look at what a transaction is, to a node its just a big long byte string. If the bytes are convertible to ASCII, you can use use the
web3.toAscii()
That may or may not give you something. For instance, here's a tx a I did on Ropsten where you get some readable input data back and some non-readable data:
https://ropsten.etherscan.io/tx/0xe4058b8f612f20600d8aae1230d93b7b5c63398ddde0a3a6aed236659f425c0e (just click the input Convert to Ascii at the bottom)
That said, the best (easiest) way to do this is to own the dapp. So when they fill out a form, you just save the input data. The next best like you said is to use Events. They are annoying, but you could have just one long event at the beginning of your contracts:
contract Test {
event Input(string desc, address _party, uint _input1, string _input2);
function somefunc(uint _input1, string _input2) returns(bool success){
Input("Input",msg.sender,_input1,_input2);
return true;
}
}
But then for other people's contracts your out of luck since you don't have this event.
Here is a more complete program than the one you provided. The only undefined part is Contract_sol_Contract
, which you did not define. Notice how privateKey
and publicKey
are computed.
import org.web3j.crypto.Credentials;
import org.web3j.crypto.ECKeyPair;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;
import java.io.IOException;
import java.math.BigInteger;
public class SO3 {
public SO3() throws IOException {
Web3j web3 = Web3j.build(new HttpService("http://localhost:8545"));
String account = web3.ethAccounts().send().getAccounts().get(0);
Credentials credentials = Credentials.create(account);
ECKeyPair keyPair = credentials.getEcKeyPair();
BigInteger privateKey = keyPair.getPrivateKey();
BigInteger publicKey = keyPair.getPublicKey();
Contract_sol_Contract contract = Contract_sol_Contract.deploy(web3, credentials, new BigInteger("240000"), new BigInteger("2400000"), props).send();
}
}
I think that the reason that web3j
deviated from web3
in requiring just the public or private key is because providing less information is a better security practice. The web3 accounts docs has this warning: The accounts private key. This should never be shared or stored unencrypted in localstorage! Also make sure to null the memory after usage.
This means passing around the entire accounts object is discouraged.
Seems the web3
authors knew they created a security issue because earlier on that same page they give this big fat warning: This package has NOT been audited and might potentially be unsafe. Take precautions to clear memory properly, store the private keys safely, and test transaction receiving and sending functionality properly before using in production!
.
Best Answer
The "ethGetBalance" method will return the balance of any given account. Pls see example below: