3

I'm trying to write function which will be transfer erc-20 tokens in hedera hashgraph.

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";    
contract Coins is ERC20 {
        constructor(string memory name_, string memory symbol_)  ERC20(name_, symbol_) {
            _mint(msg.sender, 1000000000000000000000);
        }
    }

very simple solidity contract

then i deploy it in hedera

tx, err := hedera.NewContractCreateFlow().
        SetBytecode(bytecode).
        SetGas(1_000_000).
        SetConstructorParameters(
            hedera.NewContractFunctionParameters().
                AddString("Coins").
                AddString("coin"),
        ).
        Execute(client)

then i've trying to transfer some erc-20 tokens to other address

ps, _ := hedera.NewContractFunctionParameters().
    AddAddress(hedera.AccountID{Account: 34937758}.ToSolidityAddress())
ps.AddUint256(big.NewInt(1).Bytes())

contractExecTx, err := hedera.NewContractExecuteTransaction().
    SetContractID(newContractID).
    SetGas(1000000).
    SetFunction("transfer", ps).
    Execute(client)

and i got error StatusContractRevertExecuted (33)

is it possible to use ERC-20 tokens as a usual in Ethereum? or i have to use HTS only? is it possible to use solidity contract and register it as token in Hedera?

thank you so much

blackgreen
  • 34,072
  • 23
  • 111
  • 129

2 Answers2

2

UPD: solution

looks like bytes for uint256 not compatible with hedera uint256 and big.NewInt(number).Bytes() is not working for hedera uint256

i've takes some abi lib

github.com/dcb9/go-ethereum/accounts/abi


AddUint256(abi.U256(big.NewInt(some number)))

and back to big.Int

query.GetUint256(0) // query for getting uint256

bInt := new(big.Int)
bInt.SetBytes(query.GetUint256(0))

and now it is works perfect

1

Well done for finding the solution, I've not tried it with Go web3 libraries, but had success using existing web3 libraries in conjunction with the SDK in both java and javascript, here is a repo with some examples, maybe it will also work in Go.

https://github.com/hashgraph/hedera-smart-contracts-libs-lab

Greg Scullard
  • 241
  • 1
  • 10