Smart contracts that implement nitro protocol for state channel networks on ethereum. Includes javascript and typescript support.
There is an accompanying documentation website.
A full description of nitro protocol and it's capabilities can be found in a whitepaper.
.../my-statechannel-app> npm install --save @statechannels/nitro-protocol
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import '@statechannels/nitro-protocol/contracts/interfaces/ForceMoveApp.sol';
import '@statechannels/nitro-protocol/contracts/Outcome.sol';
contract MyStateChannelApp is ForceMoveApp {
function validTransition(
VariablePart memory a,
VariablePart memory b,
uint256 turnNumB,
uint256 nParticipants
) public pure returns (bool) {
Outcome.OutcomeItem[] memory outcomeA = abi.decode(a.outcome, (Outcome.OutcomeItem[]));
Outcome.OutcomeItem[] memory outcomeB = abi.decode(b.outcome, (Outcome.OutcomeItem[]));
require(assetOutcomeA.assetOutcomeType == uint8(Outcome.AssetOutcomeType.Allocation),'outcomeA: AssetOutcomeType must be Allocation');
/* The rest of your logic */
return true;
}
}
const {
NitroAdjudicatorArtifact,
ConsensusAppArtifact,
EthAssetHolderArtifact,
Erc20AssetHolderArtifact,
TrivialAppArtifact,
TokenArtifact,
} = require('@statechannels/nitro-protocol').ContractArtifacts;
import {Channel} from '@statechannels/nitro-protocol';
const channel: Channel = {
chainId: '0x1',
channelNonce: 0,
participants: ['0xalice...', '0xbob...'],
};
import {getChannelId} from '@statechannels/nitro-protocol';
const channelId = getChannelId(channel);
We use etherlime for smart contract development.
To get started:
- Download the repo,
cd
into the directory and runyarn install
- Run
yarn install
. - Run
yarn test
.
- Run
yarn docgen
to auto-generate markdown files from compiled Solidity code (using our fork ofsolidoc
). If you change the source code you will need to recompile the contracts and re-runsolidoc
usingyarn contract:compile && yarn docgen
. - Run
cd website
- Run
yarn install
- Run
yarn start
See https://docusaurus.io/docs/en/installation for more information.
NB: you may run into difficulty running docgen / solidoc
if you have the native solc compiler installed at the incorrect version number. You may refer to the circle config.yml
at the monorepo root to check which version is being used as a part of our continuous integration.
To add a new version of the docs, follow the instructions at https://docusaurus.io/docs/en/tutorial-version. We try to keep the documentation version in sync with the @statechannels/nitro-protocol npm package.