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

eth/client: add transfer_erc20 function #197

Merged
merged 5 commits into from
Jan 2, 2023
Merged

eth/client: add transfer_erc20 function #197

merged 5 commits into from
Jan 2, 2023

Conversation

q9f
Copy link
Owner

@q9f q9f commented Jan 2, 2023

geth = Client.create "/tmp/geth.ipc"
# => #<Eth::Client::Ipc:0x000056433dfb0f28 @gas_limit=21000, @id=0, @max_fee_per_gas=0.4269e11, @max_priority_fee_per_gas=0.101e10, @path="/tmp/geth.ipc">
erc = Contract.from_file(file: "spec/fixtures/contracts/erc20.sol")
# => #<Eth::Contract::ERC20:0x000056433e09a678>
geth.deploy_and_wait(erc, "FooBar", "FOO")
# => "0xb14BD4a61E0f8d0e390A8e109e67dedb5965EEDe"
key = Key.new
# => #<Eth::Key:0x000056433d98b620 @private_key=#<Secp256k1::PrivateKey:0x000056433d98a478 @data="E\xAC\x8C\"\xFB\xEC+\xA6u'\x9E\x02@\xAFWy\x03X\"dY]\x13m\xF9\\\x15\v\xE07\xDFn">, @public_key=#<Secp256k1::PublicKey:0x000056433d989ac8>>
geth.transfer_and_wait(key.address.to_s, 1 * Unit::ETHER)
# => "0xa1a8a9e13bd54585d6e761ff31fc1db191c9bca83853e240712b190af8cc6b30"
geth.transact_and_wait(erc, "mint", key.address.to_s, 1 * Unit::ETHER)
# => "0x2e4bf86faf18f5450f5c15304c5236378937953283c8fdd15ab2fd2019cb0991"
geth.call(erc, "balanceOf", key.address.to_s)
# => 1000000000000000000
geth.transfer_erc20_and_wait(erc, "0x49eB8f597De9B22D9141392d287BAfDc80994D51", 1, sender_key: key)
# => "0x5669979670d204bc1624ac9042c28fdef7c5e26d722872026cc7bb980482e280"
geth.call(erc, "balanceOf", key.address.to_s)
# => 999999999999999999
geth.call(erc, "balanceOf", "0x49eB8f597De9B22D9141392d287BAfDc80994D51")
# => 1

fix #145

@q9f q9f added the spec-tests label Jan 2, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jan 2, 2023

Codecov Report

Merging #197 (0d3440e) into main (096d793) will decrease coverage by 0.04%.
The diff coverage is 93.33%.

❗ Current head 0d3440e differs from pull request most recent head db1e14f. Consider uploading reports for the commit db1e14f to get more accurate results

@@            Coverage Diff             @@
##             main     #197      +/-   ##
==========================================
- Coverage   99.76%   99.72%   -0.05%     
==========================================
  Files          74       74              
  Lines        4345     4375      +30     
==========================================
+ Hits         4335     4363      +28     
- Misses         10       12       +2     
Impacted Files Coverage Δ
lib/eth/client.rb 98.92% <60.00%> (-1.08%) ⬇️
spec/eth/client_spec.rb 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@q9f q9f merged commit d41b865 into main Jan 2, 2023
@q9f q9f deleted the q9f/contract/erc20 branch January 2, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Token Transfer
2 participants