Created
October 11, 2017 15:27
-
-
Save krgn/14bc5adfdb07036b2d7fcec10355899f to your computer and use it in GitHub Desktop.
fsharp nethereum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<EntryPoint>] | |
let main argv = | |
let dir = argv.[0] | |
let account = ManagedAccount(sender, password) | |
let web3 = Web3Geth(account) | |
web3.Personal.UnlockAccount.SendRequestAsync( | |
sender, | |
password, | |
Nullable(120)) | |
|> await | |
|> printfn "unlocked: %b" | |
do web3.Miner.Start.SendRequestAsync() |> await |> ignore | |
let bin = Path.Combine(dir, "FileSyncContract.bin") |> File.ReadAllText |> sprintf "0x%s" | |
let abi = Path.Combine(dir, "FileSyncContract.abi") |> File.ReadAllText | |
let receipt = | |
(abi, bin, sender, HexBigInteger(Numerics.BigInteger(900000)), null) | |
|> web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync | |
|> await | |
let contractAddress = receipt.ContractAddress | |
let contract = web3.Eth.GetContract(abi, contractAddress) | |
printfn "mined contract: %A" contract.Address | |
let testFunc = contract.GetFunction("test") | |
let multiplyFunc = contract.GetFunction("multiply") | |
let multiplyEvent = contract.GetEvent("Multiplied") | |
let filterAll = await (multiplyEvent.CreateFilterAsync()) | |
Async.Start( | |
async { | |
while true do | |
web3.Personal.UnlockAccount.SendRequestAsync( | |
sender, | |
password, | |
Nullable(120)) | |
|> await | |
|> printfn "unlocked: %b" | |
let receipt = | |
multiplyFunc.SendTransactionAndWaitForReceiptAsync( | |
sender, | |
HexBigInteger(Numerics.BigInteger(4700000)), | |
HexBigInteger(Numerics.BigInteger(7)), | |
null) | |
|> await | |
printfn "receipt: %A" receipt.Logs | |
do! Async.Sleep(1000) | |
}) | |
Async.Start( | |
async { | |
while true do | |
let logs = | |
multiplyEvent.GetFilterChanges<NewResult>(filterAll) | |
|> await | |
printfn "logs: %d" logs.Count | |
for log in logs do | |
printfn "multiplier: %d sender: %s result: %d" | |
log.Event.MulitplicationInput | |
log.Event.Sender | |
log.Event.Result | |
do! Async.Sleep(1000) | |
}) | |
while true do | |
Console.ReadLine() |> ignore | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment