-
Notifications
You must be signed in to change notification settings - Fork 56
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
Sending a transaction #7
Comments
Signing transactions is not implemented in this GEM. |
@astudnev Do you have a plan to implement it? |
No direct plan, but would be very nice |
I am thinking to implement it.... Any ideas? Someone wants to collaborate? |
Don't mean to steal anyone's thunder. But I have basic functionality for sendTransaction (not ready yet for arrays) in my library here https://github.com/hswick/w3 and I am looking for collaborators as I can only work on it part time. There is also https://github.com/EthWorks/ethereum.rb which is fairly developed |
Hey people, why reinvent the wheel, for signing transactions you can use https://github.com/se3000/ruby-eth - would be more useful to try and fix some of the quirks of that library (one of them I will fix as soon as time permits...) Then you can simply do: #================= res = web3.eth.getTransactionCount ['.....acct.......', 'pending'] tx = Eth::Tx.new({ key = Eth::Key.new priv: '....acct_private_key.....' The more tricky part (from my point of view) is to properly encode the data - this seems to be possible with web3-eth but need to test it. |
@hswick - apart from the signing, all the necessary functions to send transactions seem to be implemented in a pretty comprehensive way in the Ethereum.rb gem (https://github.com/EthWorks/ethereum.rb) which does have some minor quirks but generally works (only with parity at the moment). However, that gem does not expose most of its useful functions, such as input data encoding, so instead of trying to redo, we could work on doing that. What do you think? |
@alex-kampa I like the simplicity of ruby-eth for signing transactions. Anyone looking on this thread would probably benefit from the use of it. In regards to ethereum.rb I address this in my README. I'm a fairly opinionated person (as I think conviction makes good software), and I have actually been stealing some of the internals for w3 from ethereum.rb (which I reference). It isn't a matter of functionality, it is about design. My design isn't based on just becoming feature parity with something like web3.js, it is about surpassing it. |
@hswick I just went through your w3 library, it looks promising. I'll check it out. |
I'm also trying to send transaction as @woniesong92
then error respose
please help me. |
Any luck with that problem @marknguyen85? |
Hello @alex-kampa, In your example above:
Could you please be more clear as to what goes in the data field? it seems this is what @marknguyen85 Could be missing as well? Thank you very much. |
i've resolved with code below
@jlstr i think data is not require |
Awesome thanks! @marknguyen85 May I ask one follow up Question, How do you get a contract object? I'm trying to load it from a Ruby Hash:
Where The above does not allow me to do: Please Help. |
@jlstr I'm also problems as you with methods of constract instance |
@jlstr format to => Abi = '[]' |
Awesome! Thank you @marknguyen85, And How are you calling contract methods? |
@jlstr i found in this gem code
=> have you any idea for this processing? |
Hello @marknguyen85, I have figured it out, and let me tell you, you're in the right track, but the key is that you have to serialize the entire contract method you'll call according to the ABI Spec. Once serialized, you will get a long HEX string that looks like: That hex string goes in the data field of the TX: tx = Eth::Tx.new({ The rest is exactly as you have in your example, but remember that the to will always be the contract's address in Ethereum. Let me know if require any further help. |
The answer to your Question is very broad, in the hex strings you have pasted above, what are you trying to represent? a number (uint256)? I will teach you how I personally generate a uint256 as an example so that you have an idea of what to do next, let say you want to pass the decimal value 10 to a smart contract's method:
First you have to convert it into WEI, easy enough, just multiply by a 10^18 constant
Now, you have to convert it to hexadecimal:
Finally, pad the hexadecimal value with 0s to complete a 64 bit long hex string that's required by Ethereum:
This example will translate a decimal number like 10 into a uint256 type, I have examples for other types, but I hope this will give you an idea of how to do it. Kindly, |
@jlstr thanks |
@jlstr - some of the encoding was also done by @hswick at https://github.com/hswick/w3/blob/master/lib/w3/encoder.rb It does not seem to handle all cases though - for example arrays as inputs are probably a bit tricky, and this includes strings which are handled like arrays as far as i know. If anyone here manages to do the encoding in the most generic way, please let us know. |
BTW, the specs for the encoding are here: http://solidity.readthedocs.io/en/develop/abi-spec.html |
Thank you @alex-kampa I did use that very same spec in order to do the parsing, too bad it's so coarse. |
Is there a way to call a function (i.e. send a transaction) with this library?
If I wanted to programmatically call a function that updates blockchain state, what's the best way to do it?
The text was updated successfully, but these errors were encountered: