Skip to content
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

Signing Transactions #25

Closed
hswick opened this issue Oct 1, 2018 · 1 comment
Closed

Signing Transactions #25

hswick opened this issue Oct 1, 2018 · 1 comment

Comments

@hswick
Copy link
Owner

hswick commented Oct 1, 2018

ethereumex explains a way to do this, but it requires the Blockchain hex package. Considering, that the entire Blockchain project probably isnt necessary for this feature, it may make sense to extract those parts out.

The thinking would be something like this (taken from etheremex README):

eth_send_raw_transaction example - Payable smart contract call

Calling a smart contract method that requires computation will cost you gas or ether (if that method requires payment also). This means you will have to sign your transactions using the private key that owns some ethereum. In order to send signed transactions you will need both ABI and Blockchain hex packages.

abi_encoded_data = ABI.encode("transferFrom(address,address,uint)", [from_address, to_address, token_id])
contract_address = "0x123" |> String.slice(2..-1) |> Base.decode16(case: :mixed)

transaction_data = %Blockchain.Transaction{
    data: abi_encoded_data,
    gas_limit: 100_000,
    gas_price: 16_000_000_000,
    init: <<>>,
    nonce: 5,
    to: contract_address,
    value: 0
}
|> Blockchain.Transaction.Signature.sign_transaction(private_key)
|> Blockchain.Transaction.serialize()
|> ExRLP.encode()
|> Base.encode16(case: :lower)

Ethereumex.HttpClient.eth_send_raw_transaction("0x" <> transaction_data)
@hswick
Copy link
Owner Author

hswick commented Oct 18, 2018

0.4.2 includes the personal api as well as eth_sign

@hswick hswick closed this as completed Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant