Side-by-side CRUD patterns for Fabric chaincode and Besu smart contracts. Working code examples, testing templates, and the 5 anti-patterns that break production.
Developers waste hours translating patterns between Fabric's Go/JS/Java chaincode and Besu's Solidity contracts. The APIs are different, the state models are different, the testing tools are different — but the CRUD patterns are the same. This cheat sheet puts them side by side.
// Fabric Chaincode — Go (asset CRUD)
func (c *AssetContract) CreateAsset(ctx contractapi.TransactionContextInterface,
id, name, owner string, value int) error {
exists, err := c.AssetExists(ctx, id)
if err != nil {
return fmt.Errorf("failed to check existence: %w", err)
}
if exists {
return fmt.Errorf("asset %s already exists", id)
}
asset := Asset{ID: id, Name: name, Owner: owner, Value: value}
assetJSON, err := json.Marshal(asset)
if err != nil {
return fmt.Errorf("failed to marshal: %w", err)
}
return ctx.GetStub().PutState(id, assetJSON)
}// Besu Smart Contract — Solidity (asset CRUD)
contract AssetRegistry {
struct Asset {
string name;
address owner;
uint256 value;
bool exists;
}
mapping(string => Asset) private assets;
event AssetCreated(string indexed id, address owner);
modifier onlyOwner(string memory id) {
require(assets[id].owner == msg.sender, "Not owner");
_;
}
function createAsset(string memory id, string memory name,
uint256 value) external {
require(!assets[id].exists, "Already exists");
assets[id] = Asset(name, msg.sender, value, true);
emit AssetCreated(id, msg.sender);
}
}Enter your work email and we'll send you the complete cheat sheet with all 4 language examples, testing templates, and deployment commands.