Implementation guide

Smart contracts and chaincode: building, testing and upgrading shared rules

Sheet
A-05
Checked
Sources
13
Scope
Canada · educational
Short answer

Smart contracts are the shared business rules of a permissioned network, run identically by every node that endorses or validates a transaction. Fabric chaincode is written in Go, Node.js or Java and, by default, a majority of channel organizations must approve it; Besu runs Solidity. Treat every contract change as a tested, reviewed consortium decision.

Key takeaways
  • Fabric chaincode is written in Go, Node.js or Java and deployed by package, install, approve and commit.
  • By default a majority of a channel’s organizations must approve a Fabric chaincode definition.
  • Besu runs Solidity contracts with Ethereum tooling such as Hardhat, Remix and web3j.
  • Corda contracts run on the JVM with a flow framework for messaging; Canton executes Daml.
  • Upgrades are governance events: agree the approval rule, test plan and recovery path before go-live.

What a smart contract does in a consortium

A smart contract is code that every relevant node runs to decide whether a proposed change to the ledger is allowed and what the new state should be. In a consortium it is the written-down version of rules members have agreed: who may create a record, what fields it needs, which approvals make it final. Because several organizations run the same code and must reach the same result, contracts have to be deterministic: the same inputs must produce the same outputs on every node.

That leads to a few design habits. Keep contracts small and focused on validation and state changes. Leave heavy processing, document storage and calls to outside systems in member applications, which then submit results to the ledger. Never write personal information into contract state; see privacy patterns. And remember that contract code is shared intellectual property, so decide who owns it before anyone writes it; see IP, licensing and liability.

Hyperledger Fabric chaincode

Fabric chaincode can be written in Go, Node.js or Java. It reads and writes the world state, which lives in either LevelDB, the default embedded key-value store, or CouchDB, a separate process that supports rich queries on JSON documents. Fabric v3.1 added batched writes and reads, such as StartWriteBatch, FinishWriteBatch and GetMultipleStates. The legacy chaincode lifecycle was removed in v3.0, so new networks use the lifecycle below.

  1. Package

    The chaincode is packaged into a deployable archive.

  2. Install on peers

    Each organization installs the package on the peers that will endorse transactions.

  3. Approve a definition for your organization

    Each organization approves a chaincode definition that names the version, endorsement policy and other parameters.

  4. Commit the definition to the channel

    Once enough organizations have approved, the definition is committed and the chaincode can be used on the channel.

By default, a majority of a channel’s organizations must approve a chaincode definition before it can be committed, and the default endorsement policy also requires a majority. Endorsement policies are written with AND, OR and OutOf, for example AND(‘Org1MSP.member’, ‘Org2MSP.member’). They can be set for the whole chaincode, for a private data collection, or for an individual key through state-based endorsement, where a key-level policy overrides the chaincode policy for that key. These defaults are a starting point; the consortium should decide its own rule and record it in the charter.

Besu, Solidity and the EVM; Corda; Daml on Canton

Besu is an Ethereum client, so private Besu networks run Solidity contracts on the Ethereum Virtual Machine. It works with common Ethereum tools such as Hardhat, Remix and web3j, which gives teams a large pool of familiar tooling. Besu does not manage keys itself and pairs with Web3Signer for signing. Two cautions apply. EVM contracts are generally fixed once deployed unless an upgrade mechanism is designed in, so upgradeability is an architecture decision. And Besu’s built-in private transactions are gone: Tessera privacy was removed in 25.6.0, so every node can read every contract’s state and confidentiality must be handled at the application layer.

Corda is written in Kotlin and targets the JVM, and its contracts can be written in Java and other JVM languages. Its README describes a flow framework for communication between participants and notaries that check uniqueness. Corda states are immutable: a change creates a new state and marks the old one historic, and each node keeps a vault of its current and historic states.

Canton runs Daml, which Digital Asset publishes as “the Daml smart contract language” under Apache-2.0. Canton implements Daml’s authorization and privacy models: the submitting participant runs the Daml code and splits the transaction into views for each set of stakeholders. See Canton and Daml.

Contract models compared
FrameworkContract languageHow code reaches the networkWho approves changes
Hyperledger FabricGo, Node.js or Java chaincodePackage, install, approve and commit per channelA majority of channel organizations by default; configurable
BesuSolidity on the EVMContract deployment transactions; upgrade paths designed into the contractsSet by consortium governance and the contract design
CordaJava or other JVM languages (Corda itself is written in Kotlin)Contracts and flows deployed to participating nodesSet by the parties and the network’s governance
CantonDamlDaml models executed by the submitter and confirmed by stakeholdersSet by the parties and the synchronizer’s governance

Testing before anything touches a shared ledger

A defect in a shared contract is a shared incident: once a transaction is committed, it stays on every member’s ledger. Test more than you would for a single-organization application.

  • Unit tests for every rule, including the edge cases members argued about when writing the requirements.
  • Multi-organization integration tests on a network whose topology, endorsement policies and identities match production.
  • Negative tests: submitters without the right role, malformed inputs, replayed transactions, missing endorsements.
  • Policy tests that confirm a transaction fails when one required organization does not sign.
  • Determinism review: no clocks, random numbers or external calls that could give different nodes different answers.
  • Data review: confirm that no field could carry personal information onto the ledger. The data placement step of the residency planner helps.
  • Load tests with your own workload. Published performance figures rarely match your transaction mix, so measure your own.

Upgrade governance and audits

  1. Propose

    A change request states the business reason, the code difference, the test results and any data migration.

  2. Review independently

    Material changes get a security review by people who did not write the code. For contracts that move value or rights, commission an external audit.

  3. Approve under the charter

    Members approve under the agreed rule. In Fabric the lifecycle makes this explicit, because each organization approves the new definition.

  4. Deploy in a coordinated window

    Members install and activate the change together, with a rollback or forward-fix plan. Committed transactions cannot be undone, so recovery means a corrective change, not a reversal.

  5. Verify and record

    Confirm the new version is live on every member’s nodes and keep a register of approved versions and who approved them.

Write this process into upgrades and change control before the first deployment. For key handling during deployments, see security and key management.

What languages can Hyperledger Fabric chaincode be written in?

Go, Node.js or Java, according to the Fabric chaincode lifecycle documentation.

What is the difference between chaincode and a smart contract?

Chaincode is Fabric’s term for the program that holds smart contract logic and is deployed through the Fabric lifecycle. Elsewhere the general term “smart contract” is used; in practice the two are used interchangeably.

How do you upgrade a smart contract on a permissioned blockchain?

Through an agreed governance process. In Fabric, each organization approves a new chaincode definition and it is committed once enough have approved (a majority by default). On EVM networks such as Besu, upgradeability has to be designed into the contracts.

Do smart contracts on a private network need a security audit?

Yes, if they control value, rights or records that members rely on. A private network limits who can attack a contract but does not remove bugs, and a bad transaction cannot be erased once committed.

Mitey the yeti gesturing at a cost table
DETAIL A-05 · Mitey on this sheetMitey prices the extra developers a contract review needs.
A six-person build team instead of four
The reconciliation case with two more engineers on chaincode and testing.
A six-person build team instead of four: inputs, steps and result
Starting pointInter-company reconciliation, 6 membersA labelled worked example from the business case builder, not a real consortium.
Members6 founding, 1 joining a year10 years at a 7% real discount rate (Treasury Board 2022 guide default: 7%).
Build team (FTE)6Changed from the worked example’s default.
Consortium NPV$1,352,327Costs $12,435,525, benefits $15,839,775, payback in year 7.
Shared database NPV$1,332,938Same onboarding and integration costs; captures 70% of the benefits.
Consortium minus database$19,389
Consortium wins when a database captures less than70%The tie point: below this share of benefits, members are better off with their own ledger.
ResultThe consortium comes out ahead: NPV $1,352,327 against $1,332,938 for a shared database over 10 years, but only while a shared database would capture less than 70% of the same benefits.

What it shows: Two more engineers almost erase the consortium’s lead over the shared database: in a case this tight, contract quality has to be paid for and still argued for.

Open this example in the business case builder →Computed 2026-11-04.

Sources

Checked 2026-10-31. Rules and project status change; confirm against the source before relying on it.

  1. Hyperledger Fabric docs: Fabric chaincode lifecycle
  2. Hyperledger Fabric docs: Endorsement policies
  3. Hyperledger Fabric docs: What’s new in Hyperledger Fabric
  4. Hyperledger Fabric docs: Ledger
  5. Hyperledger Fabric v3.0.0 release notes
  6. Besu documentation
  7. Besu 25.6.0 release notes
  8. LF Decentralized Trust: Sunsetting Tessera and simplifying Hyperledger Besu
  9. Corda README (release/os/4.12)
  10. Corda key concepts: States
  11. Canton repository (Digital Asset)
  12. Daml repository (Digital Asset)
  13. Canton Network docs: How transactions work