-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync contract.method.sendTransaction returns undefined #221
Comments
The |
This is not how sendTransaction works. Can we please reopen this? |
https://github.com/ethereum/web3.js/pull/222/files - this is what I'm talking about |
@jesuscript a |
This is how AZ works. The situation with Geth is different: sendTransaction is (sort of) instantaneous: it's either rejected off the bat if you haven't unlocked your primary or accepted immediately. The bigger issue here is this: do you want to keep synchronous sendTransaction calls? In which case might as well make them work right. Or do you actually want to drop them because quite frankly blocking calls in js are nonsense? |
That's true. Currently if we are creating a contract, AZ returns new contract address . Otherwise it returns nothing. Meanwhile geth returns new contract address or transaction hash. We will unify this soon. |
For the record, Vapor will always return |
its fixed in develop -> that it will also return the txhash when calling sync. I'm working on a reliable solution to deploy contracts and getting its address, as it seems for now, you need to a custom event to the constructor. An example would be (Please threat that as a rough draft): // Soldity contract
event Created(bytes32 indexed identifier);
contract MyContract {
function MyContract(bytes32 identifier) {
Created(identifier);
}
}
// JS create contract
var MyContract = web3.eth.contract(abi);
var myContractInstance = MyContract.new('xyz1234', {from: ..., data: ..., gas: 123456})
var createdAtBlock = web3.eth.blockNumber;
// JS listen for created log
var Created = web3.eth.filter({
topics: [null, 'xyz1234'],
fromBlock: createdAtBlock,
toBlock: 'latest'
}));
Created.watch(function(error, log) {
if(!error) {
console.log('Contract created on '+ log.address);
myContractInstance.address = log.address;
// remove filter
Created.stopWatching();
}
});
// JS watch for the last next 12 blocks if the code is still at the address
web3.eth.filter('latest').watch(function(e, blockHash){
if(!e) {
var block = web3.eth.getBlock(blockHash);
if(block.number - createdAtBlock < 12) {
// check if contract stille exists, if show error to the user
if(web3.eth.getCode(myContractInstance.address).length === '0x')
alert('Contract Gone!');
}
}
}); |
@frozeman Thanks for the example! However, my use case that caused an issue was related to How do you track a specific transaction with filter.watch without using it's address? |
use go, and you get the txhash :) But the tx hash is also not set in stone, as nonce or gas changes would invalidate the hash and create a new one |
Oh if we're just returning a 'guess' then I can provide that behaviour in Vapor, but that seems dangerous. Seems like it would be most useful and least dangerous to have the synchronous method call return nothing, and the async call return the correct information after it has been sealed in a block (though, forks could still invalidate things) |
Closing this as its fixed in develop |
Can we please make it return the transaction address? Especially since the docs say that it should: https://github.com/ethereum/wiki/wiki/JavaScript-API#returns-42
The text was updated successfully, but these errors were encountered: