Lightweight/Simple
Much of the complexity is shunted to the tooling, reducing the complexity of the spec. for easier integration and porting to other languages.
DANGER
This is a preview release to get developer feedback and (hopefully) identify any gaps in the current specification. CashConnect is still under development and IS NOT yet safe for Production use.
CashConnect is a lightweight templating system that aims to provide a versatile and secure interface for Dapp <-> Wallet communications on Bitcoin Cash.
These templates are serializable to JSON and use CashASM to give them advanced scripting capabilities. They have a structure as follows:
{
name: 'Example Template',
description: 'This is an example template',
actions: {
// ... methods that can be invoked.
},
scripts: {
// ... global scripts that are re-used by Actions.
// E.g. Lock/Unlock scripts.
}
}At their bare-minimum, Actions have params (data-in), instructions (processes) and returns (data-out). In this sense, they operate like a function with instructions being a pipeline of operations that should be performed (usually, by the wallet). This pipeline-esque approach allows templates to generalize to many use-cases that might otherwise be difficult to formalize into a fixed schema.
A very simple send action may look like so:
{
//...
actions: {
// A very simple send action that pays a given sats amount to the provided address
send: {
params: {
receivingAddress: Vars.address('Receiving Address'),
sats: Vars.number('Sats to send'),
},
instructions: [
Instructions.transaction({
name: 'tx',
// Use any available UTXOs from parent wallet.
inputs: ['*'],
outputs: [
{
lockingBytecode: expr`receivingAddress`,
valueSatoshis: expr`sats`,
},
// Append change outputs to parent wallet.
'*',
]
})
],
returns: {
txHash: Vars.transactionHash('Resulting Tx Hash'),
}
}
}
}And then executed as follows:
// ... Instantiate template instance.
// Execute the send action.
const sendResult = templateInstance.executeAction('send', {
receivingAddress: Address.from('bitcoincash:...').toLockscriptBytes(),
sats: Satoshis.fromBCH('0.01').toBigInt(),
});
// The returned data (e.g. for DB persistence) is available under:
// sendResult.data;
// Broadcast the resulting transaction(s).
await blockchain.broadcastTransactions(sendResult.transactions);To ease development and testing of templates, Tooling is provided under a cashconnect-js/templates-dev package.
INFO
The recommended approach ...
Once written, Templates can then be leveraged in Bitcoin Cash Dapps (using WalletConnect as a transport) like so:
INFO
While the initial release of CashConnect targets WalletConnect as a transport, the templates are designed to be transport agnostic. This means that, in future, they can:
See Roadmap for further information.