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

[bug] input string too long for common.Address #985

Open
NCLnclNCL opened this issue Nov 13, 2023 · 2 comments
Open

[bug] input string too long for common.Address #985

NCLnclNCL opened this issue Nov 13, 2023 · 2 comments

Comments

@NCLnclNCL
Copy link

NCLnclNCL commented Nov 13, 2023

code public static async Task SendToken(string tokenAddress, string recipientAddress, string privateKey, decimal amount)
{
var Account = new Account(privateKey);
var web3 = new Web3(Account, "https://bsc-dataseed.binance.org");
string senderAddress = Web3.GetAddressFromPrivateKey(privateKey);
var abi = "[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"},{"name":"wad","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"src","type":"address"},{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"deposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":true,"name":"dst","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"dst","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Withdrawal","type":"event"}]";

    var tokenContract = web3.Eth.GetContract(abi, tokenAddress);

    var tokenAmount = BigInteger.Multiply(decimal.ToInt64(amount), 18);

    var transferFunction = tokenContract.GetFunction("transfer");
    var transferData = transferFunction.GetData(recipientAddress, tokenAmount);

    var nonce = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(senderAddress);
    var gasPrice = await web3.Eth.GasPrice.SendRequestAsync();

    var transactionInput = new TransactionInput
    {
        From = senderAddress,
        To = tokenAddress,
        Nonce = nonce,
        Gas = new HexBigInteger(900000),
        GasPrice = gasPrice,
        Value = new HexBigInteger(0),
        Data = transferData
    };
    var signedTransaction = await web3.Eth.TransactionManager.SignTransactionAsync(transactionInput);

    var transactionHash = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(signedTransaction);

    return transactionHash;
} 

stack
Unhandled exception. Nethereum.JsonRpc.Client.RpcResponseException: rlp: input string too long for common.Address, decoding into (types.LegacyTx).To: eth_sendRawTransaction
at Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response, String reqMsg)
at Nethereum.JsonRpc.Client.ClientBase.SendInnerRequestAsync[T](RpcRequestMessage reqMsg, String route)
at Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync[T](RpcRequest request, String route)
i want send token with contract tokenAddress and receiver is recipientAddress

@juanfranblanco
Copy link
Member

Your token address is not a valid address, check your input. It might help to check the getting started with smart contracts in the Nethereum playground http://playground.nethereum.com

@NCLnclNCL
Copy link
Author

Your token address is not a valid address, check your input. It might help to check the getting started with smart contracts in the Nethereum playground http://playground.nethereum.com

Can you give me an example code? I only see an example of sending eth

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

2 participants