Comments (13)
sorry for necrobump, but i found this place trying to call balanceOf
for a contract. it's been quite a headache. finally found the solution in a tutorial, thought i'd cross-post here for future people.
# prepare account address
{:ok, address } =
"0xaeaf89a26ce2986e7a948dc3adf0166301ec5c4b"
|> String.slice(2..-1)
|> Base.decode16(case: :mixed)
# prepare function to be called
data = ABI.encode("balanceOf(address)", [address])
|> Base.encode16(case: :lower)
# perform call
contract_hash = "0x88dF592F8eb5D7Bd38bFeF7dEb0fBc02cf3778a0"
{:ok, result} = Ethereumex.HttpClient.eth_call( %{ data: "0x" <> data, to: contract_hash}, "latest")
# decode result
result
|> String.slice(2..-1)
|> Base.decode16!(case: :lower)
|> :binary.decode_unsigned
# results in balance integer.
from ethereumex.
@eduardonunesp I will be working on it in the next few weeks. You can help if you want.
from ethereumex.
@ayrat555 for sure man, I'm very curious to interact within smart contracts using that lib, if you have any PR or any other repo will be awesome
from ethereumex.
@ayrat555 congratulations for your job in the PR #7 I think the next step is to create functions or helpers to call the functions on smart contract to get and alter states on smart contracts. Do you think is possible to wrap up this within that PR ?
from ethereumex.
To call smart contracts functions from json api is necessary to call send_transaction
and pass some parameters like the address of the smart contract, also is necessary to compile the solidity ABI in the data parameter, so it's important to follow the doc (https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI). I was working on that and using the module {:keccak, "~> 2.0"}
to compile the function name to sha3.
from ethereumex.
Found a module called hexate
which looks interesting to generate the params for the function calls Hexate.encode(69, 64)
which generates `"0x" <> "0000000000000000000000000000000000000000000000000000000000000045"
from ethereumex.
To generate the function signature.
{:ok, %{"result" => result}} = Ethereumex.HttpClient.web3_sha3(["baz(uint32,bool)"])
String.slice(result, 0, 12) # "0xcdcd77c0"
from ethereumex.
@eduardonunesp thanks, that's the idea
I will take a look at abi.
But we had problems with keccak library implementing merkle patricia tree. It's bettter to use keccakf1600_orig
from ethereumex.
@ayrat555 based on the code from web3.js
which parses the Smart Contract ABI
, do you think is in the scope of the project to have an ABI parser and functions to Smart Contract Functions
and listen to Smart Contract Events
?
from ethereumex.
@eduardonunesp why not? We can do that. but there is library by @izelnakri called eth, maybe it has this functionality - https://github.com/izelnakri/eth
from ethereumex.
@eduardonunesp currently I haven't built this functionality but would be more than happy to review your pull request if you are willing to contribute! Also I would appreciate if this isn't a seperate package, I'm already using several dependencies on https://github.com/izelnakri/eth, so I would like to keep it low as well.
from ethereumex.
@eduardonunesp I just found out that smart contract compilation using Json Rpc api is deprecated in both geth and parity.
I used old version of parity in #7
from ethereumex.
@ayrat555 I started to read and understand the web3.js
is the ultimate source as base for Elixir port
from ethereumex.
Related Issues (20)
- Problem following the documentation... HOT 4
- Add a clear example for sending transactions. HOT 6
- Most tests don't run on CI HOT 2
- unable to pass headers to multiple endpoints HOT 1
- How do you verify a signature? HOT 3
- eth-call is not working on Moonbeam-Network HOT 6
- engine API HOT 1
- Default http header `Content-Type: application/json`?
- Issue with web3_client_version & default behaviour targeting Anvil and more? HOT 1
- multiple nodes - reconnection HOT 1
- rlp: non-canonical integer (leading zero bytes) for *big.Int, decoding into (types.Transaction)(types.txdata).R HOT 1
- dialyzer issues when using opts argument HOT 1
- How to send ERC20 tokens from one ethereum address to another?
- Weird http pooling related error after v0.6.patch upgrade HOT 1
- Absolute IPC path HOT 1
- Feature Suggestion: ws client transport HOT 2
- Getting Jason.DecodeError, 400 in all requests HOT 3
- Batched requests don't handle errors HOT 3
- 0.8 requests failed with basic auth urls HOT 3
- Multiple endpoints HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ethereumex.