web3swift
web3swift copied to clipboard
Strange behavior on polygon with send, send erc20, and contract calls
I'm trying to send a transaction on polygon mumbai. Im using web3swift version 2.6.5. The transaction is sent correctly as I see in the Alchemy logs panel. But the transaction never become available in polyscan mumbai. The same behavior happen with send MATIC, send ERC-20 and contracts.
For example, this is the implementation for send MATIC:
let password = "PASSWORD"
let mnemonic = "12_WORDS_PHRASE"
let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: password)!
let keystoreAddress = EthereumAddress(keystore.addresses!.first!.address)!
let keystoreManager = KeystoreManager([keystore])
let endpoint = "https://polygon-mumbai.g.alchemy.com/v2/API_KEY"
let chainID = BigUInt(80001)
let mumbai = web3(provider: Web3HttpProvider(URL(string: endpoint)!, network: Networks.Custom(networkID: chainID))!)
mumbai.addKeystoreManager(keystoreManager)
let toAddress = EthereumAddress("DESTINATION_WALLET")!
let contract = mumbai.contract(Web3.Utils.coldWalletABI, at: toAddress, abiVersion: 2)!
var options = TransactionOptions.defaultOptions
options.value = Web3.Utils.parseToBigUInt("0.01", units: .eth)
options.from = keystoreAddress
options.gasPrice = .automatic
options.gasLimit = .automatic
//options.type = .eip1559
//options.maxFeePerGas = .automatic
//options.maxPriorityFeePerGas = .automatic
let tx = contract.write(
"fallback",
parameters: [AnyObject](),
extraData: Data(),
transactionOptions: options)!
let result = try! tx.send(password: password)
This is the result from tx.send():
TransactionSendingResult(transaction: Transaction
Type: Legacy
Nonce: 130
Gas price: 31831584381
Gas limit: 21000
To: 0xdA79c7C0F577748d5218a1449848A751Bb6eA88a
Value: 10000000000000000
Data: 0x
Resolved chainID: Optional(80001)
- Intrinsic chainID: Optional(80001)
- Infered chainID: Optional(80001)
v: 160037
r: 59192415274125957911004475785636246593045459813329556608938916382023215877278
s: 11537401651739707932842515715622853502948530472773493668168171920210444820025
sender: Optional("0x344a3d7734a94B767ccAAf268699d7C65818a69A")
hash: Optional("0x29f9b10318f48d7956076b9f0572cf29bc70cb8681f839bc0b8a85984bb63ad8")
, hash: "0x29f9b10318f48d7956076b9f0572cf29bc70cb8681f839bc0b8a85984bb63ad8")
Alchemy log:
Decode transaction:
Polyscan, the tx hash get unreachable after a while.
0x29f9b10318f48d7956076b9f0572cf29bc70cb8681f839bc0b8a85984bb63ad8
The same send ETH transaction from above in goerli work, I can find the txn hash in etherscan goerli.
let endpoint = "https://eth-goerli.g.alchemy.com/v2/API_KEY"
let chainID = BigUInt(5)
let goerli = web3(provider: Web3HttpProvider(URL(string: endpoint)!, network: Networks.Custom(networkID: chainID))!)
goerli.addKeystoreManager(keystoreManager)
What am I doing wrong? Or is it polygon Mumbai not supported by web3swift?
Did you find reason? I have same problem
@mb812 @bbtyou did you tried it on 3.0.3? I'm sorry to say, but 2.* version are deprecated.