Skip to content

Version 0.4.0

Choose a tag to compare

@psiemens psiemens released this 03 Jun 17:43
· 1643 commits to master since this release

address

💥 Breaking Changes

Cadence

The AuthAccount constructor signature has changed from this:

AuthAccount(publicKeys: [[Int]], code: [Int])

to this:

let account = AuthAccount(payer: AuthAccount)

This allows for another account that isn't the transaction payer to pay for the creation of a new account.

The constructor also no longer takes publicKeys and code arguments -- these fields must be provided via the addPublicKey and setCode methods.

Example

This transaction:

transaction {
  prepare() {
    let acct = AuthAccount(keys: keys, code: code)
  }
}

now becomes this:

transaction {
  prepare(signer: AuthAccount) {
    let acct = AuthAccount(payer: signer)
    for key in keys {
      acct.addPublicKey(key)
    }
    acct.setCode(code)
  }
}

This also means that the account creation transaction requires an authorizer. For cases where you were previously signing with a single payer, you can make this change to use the same payer to pay the transaction fee and account creation fee.

// Old code

tx := flow.NewTransaction().
    SetScript(createAccount).
    SetPayer(payerAddress)
  
_, = tx.SignEnvelope(payerAddress, payerKey, payerSigner)
// New code

tx := flow.NewTransaction().
    SetScript(createAccount).
    SetPayer(payerAddress).
    AddAuthorizer(payerAddress) // add payerAddress as an authorizer
  
_, = tx.SignEnvelope(payerAddress, payerKey, payerSigner)

Account Addresses

Changes introduced in #36 and #41.

  • Address length has changed from 20 bytes to 8 bytes (64 bits).
  • Address generation no longer follows a monotonic sequence; addresses are now generated in a deterministic but non-monotonic sequence.
  • Each network (Mainnet, Testnet and Emulator) uses different parameters for address generation, meaning that addresses are not compatible across networks.

AddressGenerator

The flow.AddressGenerator struct can be used to generate addresses for a specific network. Here's an example:

gen := flow.NewAddressGenerator(flow.Mainnet)

// get the current address
addressA := gen.Address()

// increment state
gen.Next()

// get the next address
addressB := gen.Address()

// skip to index 42
gen.SetIndex(42)

addressC := gen.Address()

// check if an address is valid for a network
if !addressC.IsValid(flow.Testnet) {
    fmt.Println("Invalid testnet address!")
}

Other Breaking Changes

  • flow.ZeroAddress was renamed to flow.EmptyAddress
  • flow.ZeroID was renamed to flow.EmptyID

⭐ Features

  • Transactions now support Cadence arguments, which can be used with parameterized scripts to create reusable transactions. (#43) Example
  • flow.AccountKey#SetPublicKey now automatically sets the SigAlgo field based on the provided public key. (#35)
  • flow.BlockHeader now includes a Timestamp field. (#42)
  • The flow.Mainnet, flow.Testnet and flow.Emulator ChainID constants were introduced to differentiate between different networks.

⚙️ Installing & Upgrading

go get github.com/onflow/flow-go-sdk@v0.4.0