CityCoins
Search…
Stacking
Examples of CityCoin contract functions related to stacking.

Stack CityCoins

Requires:
  • @stacks/network
  • @stacks/transactions
  • @stacks/connect-react
1
// example: stack CityCoins for the next active cycle
2
3
const NETWORK = new StacksMainnet(); // set network from @stacks/network
4
const { doContractCall } = useConnect(); // hook for Stacks Connect
5
6
const amount = 250000; // amount of CityCoins
7
const cycles = 5; // cycles to lock for
8
const amountCV = uintCV(amount);
9
const cyclesCV = uintCV(cycles);
10
11
try {
12
await doContractCall({
13
contractAddress: 'SP466FNC0P7JWTNM2R9T199QRZN1MYEDTAR0KP27',
14
contractName: 'miamicoin-core-v1',
15
functionName: 'stack-tokens',
16
functionArgs: [amountCV, cyclesCV],
17
postConditionMode: PostConditionMode.Deny,
18
postConditions: [
19
makeStandardFungiblePostCondition(
20
ownerStxAddress,
21
FungibleConditionCode.Equal,
22
amountCV.value,
23
createAssetInfo('SP466FNC0P7JWTNM2R9T199QRZN1MYEDTAR0KP27', 'miamicoin-token', 'miamicoin')
24
),
25
],
26
network: NETWORK,
27
onCancel: () => {
28
// what to do if tx is canceled / window is closed
29
console.log('Transaction canceled, please try again');
30
},
31
onFinish: result => {
32
// what to if tx is successfully broadcasted
33
console.log(`Transaction successfully broadcasted:\n${result.txId}`);
34
},
35
});
36
} catch (err) {
37
console.log(`Error: ${err.message}`);
38
}
Copied!
Copy link