Version 0.4.0
💥 Breaking Changes
Cadence
- Cadence has been upgraded to
v0.4.0: https://github.com/onflow/cadence/releases/tag/v0.4.0
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,TestnetandEmulator) 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.ZeroAddresswas renamed toflow.EmptyAddressflow.ZeroIDwas renamed toflow.EmptyID
⭐ Features
- Transactions now support Cadence arguments, which can be used with parameterized scripts to create reusable transactions. (#43) Example
flow.AccountKey#SetPublicKeynow automatically sets theSigAlgofield based on the provided public key. (#35)flow.BlockHeadernow includes aTimestampfield. (#42)- The
flow.Mainnet,flow.Testnetandflow.EmulatorChainIDconstants were introduced to differentiate between different networks.
⚙️ Installing & Upgrading
go get github.com/onflow/flow-go-sdk@v0.4.0
