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

Transfer ERC20 Tokens Using Contracts #671

Open
hasanparasteh opened this issue Nov 21, 2022 · 0 comments
Open

Transfer ERC20 Tokens Using Contracts #671

hasanparasteh opened this issue Nov 21, 2022 · 0 comments

Comments

@hasanparasteh
Copy link

hasanparasteh commented Nov 21, 2022

I'm having trouble transferring ERC20 tokens. I created the below method to construct a transaction and then broadcasting the raw transaction to the blockchain. here I have a little problem with using ABI! I call the transfer method but IDK how to provide _to & _value to the call function. Also when I call this method my code panics with below information:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Api(Rpc(Error { code: MethodNotFound, message: "The method eth_sendTransaction does not exist/is not available", data: None }))'

Here is my method declaration:

pub async fn transfer_erc20_token(
    contract: Contract<Http>,
    private_key: SecretKey,
    from: Address,
    to: Address,
    value: U256
) -> Result<H256, web3::contract::Error> {
    let c = contract.call(
         "transfer", 
         (to, value,), 
         from, 
         ContractOptions::default()
     )
     .await.unwrap();

    Ok(c)
}

And this is a piece of abi I provided to setup Contract object:

{
        "constant": false,
        "inputs": [
            {
                "name": "_to",
                "type": "address"
            },
            {
                "name": "_value",
                "type": "uint256"
            }
        ],
        "name": "transfer",
        "outputs": [
            {
                "name": "",
                "type": "bool"
            }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
}
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