You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to send an ERC20 token using this SDK and I'm having some problems. I am able to send ETH by signing and sending a raw transaction and it looks like to send an ERC20 token you pretty much do the same steps but you would attach the transfer method and parameters to the data property of the transaction. The thing is I'm not exactly sure how to convert the contract method call into the Data data type. Here is some of my code.
`//get gas price
let tt = try Blockchain.shared().network.web3.eth.getGasPrice()
gasPrice = BigUInt(Double(tt) * Double(1.40))
transaction!.gasPrice = gasPrice!
//get nonce
let nonce = try Blockchain.shared().network.web3.eth.getTransactionCount(address: tx.from)
transaction!.nonce = nonce
var options = TransactionOptions.defaultOptions
options.gasPrice = .manual(gasPrice!)
options.from = EthereumAddress(wallet.address)
options.value = amount
options.nonce = .manual(nonce)
let b = try contractAddress.method("transfer", parameters: [tx.to, amount] as [AnyObject], extraData: Data(), transactionOptions: options)`
How do I add the contract method to the transaction so I can sign and send?
var cc = try contract.method("transfer", parameters: [tx.to, amount] as! [AnyObject], extraData: Data(), transactionOptions: options)?.assemble()
try signTransaction(withWallet: wallet, transaction: &cc!, fromAddress: tx.from)
let b = try Blockchain.shared().network.web3.eth.sendRawTransactionPromise(cc!).wait()`
This transaction I can verify on the blockchain, but it is a transfer of 0eth to the erc20 contract address. it doesn't actually transfer the token to the intended destination.
//
Found an old issue in the old repository that said to use the add the keystone and use the convience function
` guard let store: BIP32Keystore = BIP32Keystore(wallet.data) else {
throw DError.Keys.keyStoreError
}
let keystoreManager = KeystoreManager([store])
Blockchain.shared().network.web3.addKeystoreManager(keystoreManager)
let result = try Blockchain.shared().network.web3.eth.sendERC20tokensWithKnownDecimals(tokenAddress: tokenAddress, from: tx.from, to: tx.to, amount: amount)?.sendPromise().wait()
print(result)`
nodeError(desc: "The method eth_sendTransaction does not exist/is not available")
Is the error I received after doing that. I traced the error to the keystore not being nil. Is this a bug or am I doing something wrong?
I was doing something wrong. I was saving the keystone to one instance and checking it on another.
new code looks like this.
`
let web3 = Blockchain.shared().network.web3
let keystoreManager = KeystoreManager([store])
web3.addKeystoreManager(keystoreManager)
let result = try web3.eth.sendERC20tokensWithKnownDecimals(tokenAddress: tokenAddress, from: tx.from, to: tx.to, amount: BigUInt(1))?.sendPromise(password: "", transactionOptions: nil).wait()
print(result) `
It sends and I can verify it on blockchain, but it doesn't transfer the token from one address to another. Its a transaction for 0ether to the token contract address.
The text was updated successfully, but these errors were encountered:
I'm trying to send an ERC20 token using this SDK and I'm having some problems. I am able to send ETH by signing and sending a raw transaction and it looks like to send an ERC20 token you pretty much do the same steps but you would attach the transfer method and parameters to the data property of the transaction. The thing is I'm not exactly sure how to convert the contract method call into the Data data type. Here is some of my code.
`//get gas price
How do I add the contract method to the transaction so I can sign and send?
`//send transaction
Excuse the forced unwrapping.
I tried
`
This transaction I can verify on the blockchain, but it is a transfer of 0eth to the erc20 contract address. it doesn't actually transfer the token to the intended destination.
//
Found an old issue in the old repository that said to use the add the keystone and use the convience function
nodeError(desc: "The method eth_sendTransaction does not exist/is not available")
Is the error I received after doing that. I traced the error to the keystore not being nil. Is this a bug or am I doing something wrong?
I was doing something wrong. I was saving the keystone to one instance and checking it on another.
new code looks like this.
`
It sends and I can verify it on blockchain, but it doesn't transfer the token from one address to another. Its a transaction for 0ether to the token contract address.
The text was updated successfully, but these errors were encountered: