Skip to content

Commit

Permalink
Add CreateFileExample
Browse files Browse the repository at this point in the history
  • Loading branch information
janaakhterov authored and qtbeee committed Nov 6, 2019
1 parent 0aa65f8 commit b5e15aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Examples/CreateFile/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Hedera

let privateKey = Ed25519PrivateKey("yourprivatekeyhere")!
let op = Operator(id: AccountId(2), privateKey: privateKey)

let client = Client(node: AccountId("0.0.3")!, address: "0.testnet.hedera.com:50211")
.setMaxTransactionFee(100_000_000)
.setOperator(op)

let fileCreateTransactionId = try! FileCreateTransaction(client: client)
.addKey(privateKey.publicKey)
.setContents("This is a test")
.setMemo("File Create Example - Swift SDK")
.setTransactionFee(1_000_000_000)
.build()
.execute()

print("File Create Example succeeded with transaction id \(fileCreateTransactionId)")
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let package = Package(
targets: ["Hedera"]),
.executable(name: "CreateAccountExample", targets: ["CreateAccountExample"]),
.executable(name: "GetFileInfoExample", targets: ["GetFileInfoExample"]),
.executable(name: "CreateFileExample", targets: ["CreateFileExample"]),
],
dependencies: [
.package(url: "https://github.com/jedisct1/swift-sodium", .exact("0.8.0")),
Expand All @@ -38,5 +39,9 @@ let package = Package(
name: "GetFileInfoExample",
dependencies: ["Hedera"],
path: "Examples/GetFileInfo"),
.target(
name: "CreateFileExample",
dependencies: ["Hedera"],
path: "Examples/CreateFile"),
]
)
4 changes: 2 additions & 2 deletions Sources/Hedera/file/FileCreateTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class FileCreateTransaction: TransactionBuilder {

body.fileCreate = Proto_FileCreateTransactionBody()

// For files and contracts expiration time needs be set to now + 7898 seconds
// For files and contracts expiration time needs be set to now + 7,890,000 seconds
// otherwise file/contract creation fails
setExpirationTime(Date(timeIntervalSinceNow: 7898))
setExpirationTime(Date(timeIntervalSinceNow: 7890000))
}

/// Set the expiration time of the file
Expand Down

0 comments on commit b5e15aa

Please sign in to comment.