Cadence

The secure, resource-oriented smart contract language built for powerful onchain logic.

What is Cadence

Cadence is a resource-oriented, high-level programming language designed for developing smart contracts. It prioritizes safety, readability, and ease of use, making it an excellent choice for developers looking to build secure and scalable blockchain applications.

Cadence introduces a novel approach to smart contract development, leveraging strong static typing, capability-based security, and an intuitive syntax inspired by Swift and Rust. With built-in protections against common vulnerabilities like reentrancy attacks and unauthorized asset transfers, Cadence ensures that smart contracts remain secure and predictable.

Think of Cadence as the next-gen language for creating powerful onchain logic and seamless experience apps — without compromising security or composability.

Why Cadence?

We built Cadence to solve the problems that
existing smart contract languages (like Solidity) couldn’t:
Secure by Design
Cadence uses resource types and type safety to prevent exploits and bugs.
Developer-Friendly
A readable, modern syntax with built-in guardrails for safer development.
Composable & Scalable
Designed for interoperability and seamless contract upgrades.
Real Ownership
Assets like NFTs and tokens are first-class citizens, with true onchain control.
Fine-Grained Permissions
Built-in capabilities make role-based access and temporary permissions easy to manage and enforce.

Powerful Features Built for Web3 Developers

Cadence 1.0 is packed with smart contract features designed for real-world scalability, security, and UX.

Core Language Concepts

Resource-Oriented Programming
  • Unique resource types that prevent duplication or loss of assets.
  • Ensures safe ownership transfers with the move (<-) operator.

Learn more

// Object users store in their account, represents currency
resource Vault {
    access(all) var balance: UFix64

    init(balance: UFix64) {
        self.balance = balance
    }
}

let vault <- create Vault(balance: 10.0)   // creation
let myVault <- vault                       // move with <-
vault.balance // Invalid: Cannot access: The old vault was moved
let vaultCopy = myVault // Invalid: Cannot make copies of resources

Strong Static Typing
  • Prevents runtime errors by enforcing type correctness at compile time.
  • Type inference reduces the need for explicit type annotations while maintaining safety.

Learn more


let name: String = "Cadence"
// Invalid: cannot assign an `Int` value to a `String` variable.
//
name = 0

// Language infers the type to be `Int` without a specification
let age = 32

Capability-Based Security
  • Granular access control that eliminates unauthorized and malicious asset access through entitlements and capabilities.
  • storage  and  public  paths allow control over the visibility of owned objects

Learn more

// Object users store in their account, represents currency
resource Vault {
    access(all) var balance: UFix64
    
    // Only those with a `Withdraw` reference to this object
    // can call this function. Only the owner can grant a Withdraw reference
    access(Withdraw) fun withdraw(amount: UFix64)
}

// Create a private withdraw capability in storage that
// can only be given to those you trust
withdrawCapability = account.capabilities.issue<auth(Withdraw) &Vault>(
    target: /storage/myVault
)

// Create a public capability that allows anyone to deposit currency
// to your account because it is created in a `public` path
signer.capabilities.publish (
    signer.capabilities.storage.issue<&Vault>(
            vaultData.storagePath
    ), 
    at: /public/vaultReceiver
)
        
Flexible Smart Contract Model
  • Upgradeable smart contracts with controlled modifications.
  • Contracts can define interfaces, enums, and composite types for better modularity.

Learn more

// Declare an interface that requires the`greet` function
access(all) contract interface Greeter {
    access(all) fun greet(): String
}

// A contract can implement interfaces to enforce correctness of implementation
access(all) contract HelloWorld: Greeter {
    access(all) fun greet(): String {
        return "Hello, Flow!"
    }
}

// Interfaces can also be used for composite types!
access(all) resource interface Balance {
    access(all) var balance: UFix64
}

Built-in Safety Mechanisms
  • Preconditions & Postconditions to enforce correct execution.
  • No reentrancy vulnerabilities, preventing most common exploits found in Solidity.

Learn more


access(all) fun withdraw(amount: UFix64): @Vault {
  pre {
    amount <= self.balance: "Amount to withdraw cannot be more than the balance!"
  }
  post {
    result.balance == before(result.balance) - amount: "Wrong amount withdrawn!"
  }
  self.balance = self.balance - amount
  return <-create Vault(balance: amount)
}

// Object users store in their account, represents currency
resource Vault {
    access(all) var balance: UFix64

    init(balance: UFix64) {
        self.balance = balance
    }
}

let vault <- create Vault(balance: 10.0)   // creation
let myVault <- vault                       // move with <-
vault.balance // Invalid: Cannot access: The old vault was moved
let vaultCopy = myVault // Invalid: Cannot make copies of resources



let name: String = "Cadence"
// Invalid: cannot assign an `Int` value to a `String` variable.
//
name = 0

// Language infers the type to be `Int` without a specification
let age = 32


// Object users store in their account, represents currency
resource Vault {
    access(all) var balance: UFix64
    
    // Only those with a `Withdraw` reference to this object
    // can call this function. Only the owner can grant a Withdraw reference
    access(Withdraw) fun withdraw(amount: UFix64)
}

// Create a private withdraw capability in storage that
// can only be given to those you trust
withdrawCapability = account.capabilities.issue<auth(Withdraw) &Vault>(
    target: /storage/myVault
)

// Create a public capability that allows anyone to deposit currency
// to your account because it is created in a `public` path
signer.capabilities.publish (
    signer.capabilities.storage.issue<&Vault>(
            vaultData.storagePath
    ), 
    at: /public/vaultReceiver
)
        
// Declare an interface that requires the`greet` function
access(all) contract interface Greeter {
    access(all) fun greet(): String
}

// A contract can implement interfaces to enforce correctness of implementation
access(all) contract HelloWorld: Greeter {
    access(all) fun greet(): String {
        return "Hello, Flow!"
    }
}

// Interfaces can also be used for composite types!
access(all) resource interface Balance {
    access(all) var balance: UFix64
}


access(all) fun withdraw(amount: UFix64): @Vault {
  pre {
    amount <= self.balance: "Amount to withdraw cannot be more than the balance!"
  }
  post {
    result.balance == before(result.balance) - amount: "Wrong amount withdrawn!"
  }
  self.balance = self.balance - amount
  return <-create Vault(balance: amount)
}

Advanced Features


access(all) view fun sayHello(name: String): String {
  return "Hello, \(name)"
}

access(all) event SignatureVerified(publicKey: String, signature: String)

let pk = PublicKey(
    publicKey: "96142CE0C5ECD869DC88C8960E286AF1CE1B29F329BA4964213934731E65A1DE480FD43EF123B9633F0A90434C6ACE0A98BB9A999231DB3F477F9D3623A6A4ED".decodeHex(),
    signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
)

let signature = "108EF718F153CFDC516D8040ABF2C8CC7AECF37C6F6EF357C31DFE1F7AC79C9D0145D1A2F08A48F1A2489A84C725D6A7AB3E842D9DC5F8FE8E659FFF5982310D".decodeHex()
let message : [UInt8] = [1, 2, 3]

let isValid = pk.verify(
    signature: signature,
    signedData: message,
    domainSeparationTag: "",
    hashAlgorithm: HashAlgorithm.SHA2_256
)

if isValid { emit SignatureVerified(publicKey: publicKey, signature: signature)

transaction {
	
	// Authorize with multiple accounts
	// Only one needs to be the payer
  prepare(acct1: &Account, acct2: &Account) {
    log("Acquire things from both authorizing accounts' storage")
  }
  execute {
	  // Call multiple contracts in a single transaction
	  FooContract.foo()
	  BarContract.bar()
  }
  post {
	  FooContract.callCount == before(FooContract.callCount + 1):
		  "Post-assertions must pass or the whole transaction reverts"
  }
}

// Standard way for a project to represent its basic metadata
access(all) struct Display {
  access(all) let name: String
  access(all) let description: Address
  access(all) let thumbnail: {File}
}

// Standard way for a resource object
// to return arbitrary metadata views that it supports
access(all) resource interface Resolver {

    // Caller specifies which type of metadata it is looking for
    // and the function returns the relevant representation
    access(all) fun resolveView(_ view: Type): AnyStruct?
}

access(all) attachment Skin for GamePiece.NFT {
    access(all) let skinType: String

    init(_ skinType: String) {
        self.skinType = skinType
    }
}

access(all) fun addAttachmentTo(
	nft: @GamePiece.NFT,
	skinType: String
): @GamePiece.NFT {
	if nft[Skin] != nil {
		// Skin attachment already attached - return
		return <- nft
	}
	// Attach the Skin & return
	return <- attach Skin(skinType) to <- nft
}

User-Friendly Syntax
  • Inspired by Swift and Rust, making it intuitive and easy to read.
  • Reduces developer friction with clear, explicit code structures.

Learn more


access(all) view fun sayHello(name: String): String {
  return "Hello, \(name)"
}

Blockchain Native Features
  • Efficient storage management using structured account storage.
  • Native event support for on-chain event tracking.
  • Integrated cryptography for digital signatures and hashing.

Learn more

access(all) event SignatureVerified(publicKey: String, signature: String)

let pk = PublicKey(
    publicKey: "96142CE0C5ECD869DC88C8960E286AF1CE1B29F329BA4964213934731E65A1DE480FD43EF123B9633F0A90434C6ACE0A98BB9A999231DB3F477F9D3623A6A4ED".decodeHex(),
    signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
)

let signature = "108EF718F153CFDC516D8040ABF2C8CC7AECF37C6F6EF357C31DFE1F7AC79C9D0145D1A2F08A48F1A2489A84C725D6A7AB3E842D9DC5F8FE8E659FFF5982310D".decodeHex()
let message : [UInt8] = [1, 2, 3]

let isValid = pk.verify(
    signature: signature,
    signedData: message,
    domainSeparationTag: "",
    hashAlgorithm: HashAlgorithm.SHA2_256
)

if isValid { emit SignatureVerified(publicKey: publicKey, signature: signature)

Gas-less Experiences & New Business Models
  • Separate transaction logic to enable gas-less experiences sponsored by applications.
  • Protocol-level multicall to combine multiple transactions into one with a single approval.
  • Supports atomic swaps, multisig, and multiauth transactions.
  • Enables new business models like freemium experiences, subscriptions, and removing third-party dependencies.

Learn more

transaction {
	
	// Authorize with multiple accounts
	// Only one needs to be the payer
  prepare(acct1: &Account, acct2: &Account) {
    log("Acquire things from both authorizing accounts' storage")
  }
  execute {
	  // Call multiple contracts in a single transaction
	  FooContract.foo()
	  BarContract.bar()
  }
  post {
	  FooContract.callCount == before(FooContract.callCount + 1):
		  "Post-assertions must pass or the whole transaction reverts"
  }
}

Future-proof Interoperable Assets
  • Custom metadata at the asset level ensures future interoperability with evolving standards.
  • Guaranteed backward compatibility for existing assets and smart contracts.
  • Metadata unlocks new features such as readable royalties by any exchange or adding creator social media links in NFTs for application frontends.

Learn more

// Standard way for a project to represent its basic metadata
access(all) struct Display {
  access(all) let name: String
  access(all) let description: Address
  access(all) let thumbnail: {File}
}

// Standard way for a resource object
// to return arbitrary metadata views that it supports
access(all) resource interface Resolver {

    // Caller specifies which type of metadata it is looking for
    // and the function returns the relevant representation
    access(all) fun resolveView(_ view: Type): AnyStruct?
}

Modable Contracts
  • Attachments in Cadence 1.0 allow developers to add additional data and functionality to existing contracts and types without requiring permission from the original contract author.
  • Empowers communities to evolve and extend products permissionlessly, enabling new applications such as:
    • Fact-checking in SocialFi.
    • Extendable games.
    • NFTs enhanced with accessories or DeFi yield bonuses.

Learn more

access(all) attachment Skin for GamePiece.NFT {
    access(all) let skinType: String

    init(_ skinType: String) {
        self.skinType = skinType
    }
}

access(all) fun addAttachmentTo(
	nft: @GamePiece.NFT,
	skinType: String
): @GamePiece.NFT {
	if nft[Skin] != nil {
		// Skin attachment already attached - return
		return <- nft
	}
	// Attach the Skin & return
	return <- attach Skin(skinType) to <- nft
}

Cadence vs Solidity vs Rust

How Cadence Stacks Up
Feature
Solidity
Rust
Cadence
Custom Resource Types
Not
Not
Unlimited
Resource Security
Not
Not
Yes
Flexible Semantics
Not
Not
Yes
Modular Procedures
Not
Yes
Yes
Reusable Execution Procedures
Not
Not
Yes
Easy to Learn
Yes
Not
Yes
Memory Safety
Not
Yes
Yes
Fast Compilation
Not
Not
Yes
Custom and Private Resource Types
Not
Not
Yes
Embedded Re-entrancy Attack On-Chain Protection
Not
Not
Yes
Single Mutable Reference to Prevent Mass Manipulation
Not
Yes
Yes
Module Isolation for Functional
Not
Yes
Yes
Direct Integration of Programs with Digital Assets
Not
Not
Yes
Built-in Support for NFTs
Limited
Not
Full Support
Event Emission for State Changes
Yes
Not
Yes
Capability-Based Access Control
Not
Limited
Yes
Transaction-Based Architecture
Limited
Limited
Yes
Readable and Developer-Friendly Syntax
Moderate
Not
High
Runtime Type Safety
Not
Yes
Yes
Ownership and Access Control
Limited
Yes
Yes
First-Class Resource-Oriented Programming Language
Not
Not
Yes
Access Control on Resources with Auth Accounts
Not
Not
Yes
Storage-Specific APIs for Developers
Not
Not
Yes
Support for Complex Token Economics (e.g., NFTs)
Not
Not
Yes

Start Building with Cadence

Explore tutorials, docs, and the Cadence playground.