我一直在尝试在 Swift 中使用带有 JavascriptCore 的web3库。通过运行创建一个 web3 实例
var web3 = new Web3(new Web3.providers.HttpProvider("[the provider im using]"))
这是我试图在 Swift 中执行此操作的代码:
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)
}
我尝试打印出 latestBlockNumber、web3、fn 和 fn1,它们都返回 undefined
有任何想法吗?