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

"Internal error: User denied account access." Need help please, thanks! #164

Open
Karthik144 opened this issue Jun 22, 2023 · 1 comment

Comments

@Karthik144
Copy link

I'm trying to send USDC from one account to another. The code I've attached below worked when we tried sending a dummy erc-20 token. Now, when I try sending USDC from my account to another, I get the following error: Error(code: -32603, message: "Internal error: User denied account access.")

    // Send transaction (ERC-20 token)
    func sendTransaction(magic: Magic, userPublicAddress: String, amount: Double){

        do{

            // 3nd instance of web3
            let web3 = Web3(provider: magic.rpcProvider)

            // Create usdc contract instance
            let contractAddress = try EthereumAddress(hex: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", eip55: false)
            let contract = web3.eth.Contract(type: GenericERC20Contract.self, address: contractAddress)

            let exponent = 18
            let ten = Decimal(10)
            let result = NSDecimalNumber(decimal: pow(ten, exponent))

            let amount = NSDecimalNumber(value: amount)
            let amountInWei = result.multiplying(by: amount)
            let convertedWeiType = BigUInt(amountInWei.stringValue) ?? 0

//            print("Converted Wei Amount: \(convertedWeiType)")

            // Send some tokens to another address (signing will be done by the node)
            let myAddress = try EthereumAddress(hex: userPublicAddress, eip55: false)

            firstly {
                web3.eth.getTransactionCount(address: myAddress, block: .latest)
            }.then { nonce in

                try contract.transfer(to: EthereumAddress(hex: "0xA741b63997bbF5AaC72bd36380533aaE0f419b14", eip55: false), value: BigUInt(convertedWeiType)).send(
                    nonce: nonce,
                    from: EthereumAddress(hex: userPublicAddress, eip55: false),
                    value: 0,
                    gas: 150000,
                    gasPrice: EthereumQuantity(quantity: 21.gwei)
                )
            }.done { txHash in
                // Success
                print("Tnx Hash (WalletViewModel): \(txHash)")

            }.catch { error in
                print("sendTransaction, WalletViewModel")
                print(error)
            }


        } catch {
            print("sendTransaction, WalletViewModel")
            print(error)
        }

    } //: SEND TRANSACTION
@Karthik144 Karthik144 changed the title "Internal error: User denied account access." "Internal error: User denied account access." Need help please, thanks! Jun 22, 2023
@koraykoska
Copy link
Member

@Karthik144 This is most likely an RPC error. I don't see anything wrong with your code

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