I have been trying to use the web3 library with JavascriptCore in Swift. A web3 instance is created by running
var web3 = new Web3(new Web3.providers.HttpProvider("[the provider im using]"))
This is the code I am trying to do this in Swift with:
if let url = Bundle.main.url(forResource: "web3", withExtension: "js"){
let lib = try! String(contentsOfFile: url.path)
let jsvirtualmachine = JSVirtualMachine()
let context = JSContext(virtualMachine: jsvirtualmachine)
context.evaluateScript(lib)
let web3 = context.evaluateScript("var web3 = new Web3(new Web3.providers.HttpProvider('[myprovider]')")
let fn = context.objectForKeyedSubscript("web3")
let fn1 = fn?.construct(withArguments: [])
let latestBlockNumber = context.evaluateScript("web3.eth.blockNumber")
print(latestBlockNumber)
}
I have tried printing out latestBlockNumber, web3, fn, and fn1 and all of them return undefined