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

Token Transfer #145

Closed
gouravnaik opened this issue Aug 28, 2022 · 6 comments · Fixed by #197
Closed

Token Transfer #145

gouravnaik opened this issue Aug 28, 2022 · 6 comments · Fixed by #197
Labels
bug Something isn't working spec-tests

Comments

@gouravnaik
Copy link

Hi,

I am trying to transfer some of my tokens to another address and here are the steps I followed.

cli = Eth::Client.create "https://polygon-rpc.com"
my_key = Eth::Key.new priv: "268be6f4a68c40f6862b7ac9aed8f701dc25a95ddb9a44d8b1f520b75f440a9a"

token_address = "0x7CdC0421469398e0F3aA8890693d86c840Ac8931" //Azuki Token(ERC20)
erc20_abi = ERC20ABI
token_name = "AZUKI"

contract = Eth::Contract.from_abi(name: token_name, address: token_address, abi: erc20_abi)

cli.transact_and_wait(contract, "transfer", account_public_address, '10000000000000000', my_key)

But getting an error

/eth-0.5.6/lib/eth/abi.rb:52:in `block in encode': undefined method `size' for nil:NilClass (NoMethodError)

        .map { |i| parsed_types[i].size or 32 }

I feel the issue is in lib/eth/abi.rb in line 52

@q9f q9f added bug Something isn't working documentation Improvements or additions to documentation labels Sep 26, 2022
@q9f
Copy link
Owner

q9f commented Sep 26, 2022

Yes, this is something we need to work on for sure!

@skeevis
Copy link

skeevis commented Oct 6, 2022

@gouravnaik have you been able to get past this issue?

@gouravnaik
Copy link
Author

gouravnaik commented Dec 20, 2022

@gouravnaik have you been able to get past this issue?

I am generating data and then send the transaction. Steps I am using currently @skeevis

def self.get_transfer_data(recipient, amount)
		transfer_method = "0xa9059cbb"  #Encoded Abi for transfer method name
		binary_data = Eth::Abi.encode(["address","uint256"],[recipient.public_key, amount])
		hex_data = binary_data.unpack('H*').first
		data = transfer_method+hex_data
	end
def self.token_transfer(chainId, token, amount, recipient, sender)
	transfer_data = MyDapp.get_transfer_data(recipient,amount)
	data = Hash["chainId", chainId, "to", token, "data", transfer_data]
	payload = create_payload(data, sender.public_key)
	send_transaction(payload, sender)
end

@q9f
Copy link
Owner

q9f commented Dec 29, 2022

Should be addressed in #191 - I'll make sure to write some tests.

@q9f q9f added spec-tests and removed documentation Improvements or additions to documentation labels Dec 29, 2022
@q9f
Copy link
Owner

q9f commented Jan 2, 2023

Confirming this should be fixed in #191

geth = Client.create "/tmp/geth.ipc"
# => #<Eth::Client::Ipc:0x0000557f2508dc80 @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:0x0000557f2517b160>
geth.deploy_and_wait(erc, "FooBar", "FOO")
# => "0x582738E45b3Ed823709F7A251352f55E4a6f146E"
erc.address
# => "0x582738E45b3Ed823709F7A251352f55E4a6f146E"
geth.call(erc, "name")
# => "FooBar"
geth.call(erc, "symbol")
# => "FOO"
geth.call(erc, "decimals")
# => 18
geth.transact_and_wait(erc, "mint", geth.default_account.to_s, 1 * Unit::ETHER)
# => "0x5246c13331ed7868e623e2a442879891e4b6e6170f2d7091fa7f56962cd647ec"
geth.call(erc, "balanceOf", geth.default_account.to_s)
# => 1000000000000000000
adr = Key.new.address.to_s
# => "0x49eB8f597De9B22D9141392d287BAfDc80994D51"
geth.transact_and_wait(erc, "transfer", adr, 1)
# => "0xf13020c546dffaac15b3e804b61db183a47947c860aad9418cc894822d4f1fa1"
geth.call(erc, "balanceOf", geth.default_account.to_s)
# => 999999999999999999

@q9f
Copy link
Owner

q9f commented Jan 2, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working spec-tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants