xaviarias on github-actions
Fix duplicated dependencies (compare)
xaviarias on github-actions
Fix duplicated dependencies (compare)
@conor10
We deployed the same contract using web3.js to the same (private) geth node.
g$ geth version
Geth
Version: 1.5.9-stable
Git Commit: a07539fb88db7231d18db918ed7a6a4e32f97450
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.7.3
OS: linux
GOPATH=
GOROOT=/usr/lib/go-1.7
This is the transaction receipt:
{
"blockHash": "0xf2d36a31d5fa687615b5df6cde1a4b56c692d07b8ce302d6055cf353add07532",
"blockNumber": 50017,
"contractAddress": "0x0509792e0ed7e8e23f3d34b458a266a85512186f",
"cumulativeGasUsed": 1048006,
"from": "0xd16336a9f47074ca5fb539b972f7e4451f25a997",
"gasUsed": 1048006,
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root": "0x0dd342b1f9c7b3e7cacc97de56068545fd7a9c4e7156269117cd654c7661ff01",
"to": null,
"transactionHash": "0xd486ecbf1139a841c4043c2a616af382afe00976034cd6210a1f7d62edcdb32b",
"transactionIndex": 0
}
library | gas used |
---|---|
web3.js | 1048006 |
web3j | 4300000 |
However, there is still one difference between our two scenarios, Java and Javascript:
solc.js
version 0.4.9
/usr/local/bin/solc
version 0.4.9+commit.364da425.Darwin.appleclang
yep - I also prepared that suggestion this moment :) ------->
There is no constructor present, only one private contract variable:
mapping(address => OtherContract[]) private otherContracts;
I compared the ABI and BIN data generated by solc.js
and the binary solc
distribution (with and without the --optimize
flag). The ABIs are the same, the BINs differ.
I will now generate the wrappers based on the BINs created by solc.js and look what happens when deploying them with Java...
@conor10
When deploying the contract using the abi/bin created with solc.js I get the same result:
My Javascript code is test code. I do not sign the transaction and I unlocked the account on the server side.
function deploy(contract, user) {
web3.eth.contract(contract.abi).new({
data: contract.binary,
from: user,
gas: TX_COST_LIMIT // = "3141592"
}, (error, contractInstance) => /* handler code */)
}
For the Java code I copied the wallet from the server side to the client side because the contract wrappers need credentials.
I created a Transaction with Java to deploy the contract (using the Javascript Binary):
String from = "0x<my-user>";
EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(
from, DefaultBlockParameterName.LATEST).send();
BigInteger nonce = ethGetTransactionCount.getTransactionCount();
String BINARY = "0x<my-binary>";
Transaction transaction = Transaction.createContractTransaction(
from,
nonce,
gasPrice,
gasLimit,
gasValue,
BINARY);
EthSendTransaction transactionResponse =
web3j.ethSendTransaction(transaction).send();
String transactionHash = transactionResponse.getTransactionHash();
`
Same result. Transaction receipt:
{
"blockHash": "0x1156e969c888585cc11269c5d5d3cbef79bb719afddaa669a3ca31cb7b9ec5b1",
"blockNumber": 51089,
"contractAddress": "0x5df2c361206dc35ae03fc8049bbe1340e28a7948",
"cumulativeGasUsed": 4300000,
"from": "0xd16336a9f47074ca5fb539b972f7e4451f25a997",
"gasUsed": 4300000,
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root": "0xfcbd82026383e04e2bd5a062b8ff03c42b637ae37a01d2a0a6ea096ba37087ef",
"to": null,
"transactionHash": "0x86d96471ceb7eb7059e04376a1bdd8ddda86addf399a9b0796a3d045309c8912",
"transactionIndex": 0
}
I could now go s step backwards and create a simpler contract.
But the question remains: Why behave web3j and web3js different.
I could also change the contract and variable names and publish them (in a private gist?) for further investigation.
Web3j web3j = Web3jFactory.build(new HttpService(url));
List<Type> inputParameters = new ArrayList<>();
List<TypeReference<?>> outputParameters = new ArrayList<>();
Function function = new Function("getManufacturer",
inputParameters,
outputParameters);
String functionEncoder = FunctionEncoder.encode(function);
EthCall response = web3j.ethCall(
Transaction.createEthCallTransaction(contractAddress, functionEncoder),
DefaultBlockParameterName.LATEST
).sendAsync().get();
List<Type> someType = FunctionReturnDecoder.decode(response.getValue(), function.getOutputParameters());
Type resault = someType.get(0);
String a = resault.toString();
Log.d("MainActitity", a + "111");
but the Type resault size is 0. someone know what's wrong?List<Type>
pragma solidity ^0.4.4;
import "./usingOraclize.sol";
contract QuerySensor is usingOraclize {
event newOraclizeQuery(string indexed description);
event newQuerySensor(string indexed price);
event res(string indexed desc);
event querySensorStarted(string indexed descp);
function QuerySensor() {
querySensorStarted("Query Sensor INITIATED");
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) throw;
newQuerySensor(result);
}
function update() payable {
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query("URL", "xml(https://www.fueleconomy.gov/ws/rest/fuelprices).fuelPrices.diesel");
}
function hw() {
res("hello world");
}
}