How to create raw transaction using web3swift?

1.1k Views Asked by At

I'm working on a project related to blockchain and need to figure out how raw transaction can be possible. I got no reference for this as of now.

I have tried matterinc/web3swift but unable to get exact thing.

1

There are 1 best solutions below

0
Shivang Pandey On
var options = Web3Options.defaultOptions()

options.gasLimit = BigUInt(21000)

options.from = self.bip32keystore?.addresses?.first!

let amountDouble = Int((Double(amount) ?? 0.0)*pow(10, 18))

let am = BigUInt.init(amountDouble)

options.value = am

let estimatedGasResult =   self.web3Rinkeby?.contract(Web3.Utils.coldWalletABI, at: toaddress)!.method(options: options)!.estimateGas(options: nil)

guard case .success(let estimatedGas)? = estimatedGasResult else {return}

options.gasLimit = estimatedGas

var intermediateSend = self.web3Rinkeby?.contract(Web3.Utils.coldWalletABI, at: toaddress, abiVersion: 2)!.method(options: options)!

intermediateSend = self.web3Rinkeby?.contract(Web3.Utils.coldWalletABI, at: toaddress, abiVersion: 2)!.method(options: options)!

let sendResult = intermediateSend?.send(password: pass)

switch sendResult {

    case .success(let r)?:

    print("Sucess",r)

  case .failure(let err)?:

  print("Eroor",err)

 case .none:

 print("sendResultBip32",sendResult)

 }     

See this blog, In this blog, I have an account as well as create a transaction in Ether and ERC20 token.

https://medium.com/@shivangpandey195/getting-started-with-web3swift-1a2454481f70