Signing
Signing can be done in various ways. Either manually, by signing the hash of the
transaction or with a wallet. There's currently two options in @kadena/client
to sign with a wallet:
Manually signing the transaction
The unsignedTransaction can be pasted into the SigData
of Chainweaver.
The createTransaction
function will return the transaction. The hash will be
calculated and the command will be serialized.
Integrated sign request to Chainweaver desktop
Using the transaction
we can send a sign request to Chainweaver.
Note: This can only be done using the desktop version, not the web version, as it's exposing port 9467 .
import { signWithChainweaver } from '@kadena/client';
// use the transaction, and sign it with Chainweaver
const signedTransaction = signWithChainweaver(unsignedTransaction)
.then(console.log)
.catch(console.error);
import { signWithChainweaver } from '@kadena/client';
// use the transaction, and sign it with Chainweaver
const signedTransaction = signWithChainweaver(unsignedTransaction)
.then(console.log)
.catch(console.error);
To send the transaction to the blockchain, continue with Send a request to the blockchain
Signing with a WalletConnect compatible wallet
There's several steps to setup a WalletConnect connections and sign with WalletConnect.
- Setting up the connection using
ClientContextProvider.tsx
- Use
signWithWalletConnect
to request a signature from the wallet (Transaction.tsx
)[https://github.com/kadena-io/wallet-connect-example/blob/2efc34296f845aea75f37ab401a5c49081f75b47/src/components/Transaction.tsx#L104 ]
Using the commandBuilder
You may prefer to not generate JavaScript code for your contracts or use
templates. In that case, you can use the commandBuilder
function to build a
command and submit the transaction yourself:
import { Pact } from '@kadena/client';
const client = getClient(
'https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/8/pact',
);
const unsignedTransaction = Pact.builder
.execution('(format "Hello {}!" [(read-msg "person")])')
// add signer(s) if its required
.addSigner('your-pubkey')
// set chian id and sender
.setMeta({ chainId: '8', sender: 'your-pubkey' })
// set networkId
.setNetworkId('mainnet01')
// create transaction with hash
.createTransaction();
// Send it or local it
client.local(unsignedTransaction);
client.submit(unsignedTransaction);
import { Pact } from '@kadena/client';
const client = getClient(
'https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/8/pact',
);
const unsignedTransaction = Pact.builder
.execution('(format "Hello {}!" [(read-msg "person")])')
// add signer(s) if its required
.addSigner('your-pubkey')
// set chian id and sender
.setMeta({ chainId: '8', sender: 'your-pubkey' })
// set networkId
.setNetworkId('mainnet01')
// create transaction with hash
.createTransaction();
// Send it or local it
client.local(unsignedTransaction);
client.submit(unsignedTransaction);
Using FP approach
This library uses a couple of utility functions in order to create pactCommand
you can import those function from @kadena/client/fp
if you need more
flexibility on crating command like composing command or lazy loading.
Here are two examples to demonstrate this:
Building a simple transaction from the contractnext:
Send a request to the blockchain