Web3.swift
Web3.swift copied to clipboard
"Internal error: User denied account access." Need help please, thanks!
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 This is most likely an RPC error. I don't see anything wrong with your code