Reference examples for integrating with the AutoShare Soroban contract.
All Stellar CLI invocations target testnet; swap --network testnet for --network mainnet in production.
Creates a new AutoShare group and locks in the initial payment for usage_count usages.
Parameters
| Name | Type | Description |
|---|---|---|
id |
BytesN<32> |
Unique group identifier (32-byte hex) |
name |
String |
Human-readable group name |
creator |
Address |
Wallet address of the creator |
usage_count |
u32 |
Number of usages to pre-purchase |
payment_token |
Address |
Token contract address used for payment |
Stellar CLI
stellar contract invoke \
--id <CONTRACT_ID> \
--source creator-key \
--network testnet \
-- \
create \
--id 0000000000000000000000000000000000000000000000000000000000000001 \
--name "Team Alpha Plan" \
--creator GABC1234...XYZ \
--usage_count 100 \
--payment_token CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSCExpected outcome
- A new group is stored on-chain with
is_active = trueandusage_count = 100. - Contract emits
AutoshareCreated { creator, group_id }. - The creator's wallet is debited
usage_count × usage_feetokens.
JavaScript / TypeScript SDK
import { Contract, SorobanRpc, TransactionBuilder, Networks, BASE_FEE } from "@stellar/stellar-sdk";
const CONTRACT_ID = "<CONTRACT_ID>";
const server = new SorobanRpc.Server("https://soroban-testnet.stellar.org");
const groupId = Buffer.alloc(32, 0);
groupId[31] = 1; // unique id bytes
const tx = new TransactionBuilder(creatorAccount, {
fee: BASE_FEE,
networkPassphrase: Networks.TESTNET,
})
.addOperation(
contract.call(
"create",
xdr.ScVal.scvBytes(groupId), // id
nativeToScVal("Team Alpha Plan"), // name
nativeToScVal(creatorAddress, { type: "address" }), // creator
nativeToScVal(100, { type: "u32" }), // usage_count
nativeToScVal(tokenAddress, { type: "address" }), // payment_token
)
)
.setTimeout(30)
.build();Tops up an existing group by purchasing additional usages.
Parameters
| Name | Type | Description |
|---|---|---|
id |
BytesN<32> |
Group identifier |
additional_usages |
u32 |
Number of usages to add |
payment_token |
Address |
Token used for payment |
payer |
Address |
Address authorising the payment |
Stellar CLI
stellar contract invoke \
--id <CONTRACT_ID> \
--source payer-key \
--network testnet \
-- \
topup_subscription \
--id 0000000000000000000000000000000000000000000000000000000000000001 \
--additional_usages 50 \
--payment_token CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC \
--payer GABC1234...XYZExpected outcome
usage_countfor the group increases by50.- Payer is debited
50 × usage_feetokens. - A
PaymentHistoryrecord is appended for the payer and the group.
JavaScript / TypeScript SDK
const tx = new TransactionBuilder(payerAccount, {
fee: BASE_FEE,
networkPassphrase: Networks.TESTNET,
})
.addOperation(
contract.call(
"topup_subscription",
xdr.ScVal.scvBytes(groupId),
nativeToScVal(50, { type: "u32" }),
nativeToScVal(tokenAddress, { type: "address" }),
nativeToScVal(payerAddress, { type: "address" }),
)
)
.setTimeout(30)
.build();Deactivates a group. Only the creator can call this. The group data is preserved on-chain for audit purposes.
Parameters
| Name | Type | Description |
|---|---|---|
id |
BytesN<32> |
Group identifier |
caller |
Address |
Must match the group's creator address |
Stellar CLI
stellar contract invoke \
--id <CONTRACT_ID> \
--source creator-key \
--network testnet \
-- \
deactivate_group \
--id 0000000000000000000000000000000000000000000000000000000000000001 \
--caller GABC1234...XYZExpected outcome
- Group
is_activeis set tofalse. - Contract emits
GroupDeactivated { creator, group_id }. - Subsequent payment attempts against the group will fail with an error.
Error cases
| Error | Cause |
|---|---|
Unauthorized |
caller does not match the group creator |
GroupNotFound |
No group exists for the given id |
GroupAlreadyInactive |
Group is already deactivated |
JavaScript / TypeScript SDK
const tx = new TransactionBuilder(creatorAccount, {
fee: BASE_FEE,
networkPassphrase: Networks.TESTNET,
})
.addOperation(
contract.call(
"deactivate_group",
xdr.ScVal.scvBytes(groupId),
nativeToScVal(creatorAddress, { type: "address" }),
)
)
.setTimeout(30)
.build();Use activate_group with the same id and creator caller to restore the group.
stellar contract invoke \
--id <CONTRACT_ID> \
--source creator-key \
--network testnet \
-- \
activate_group \
--id 0000000000000000000000000000000000000000000000000000000000000001 \
--caller GABC1234...XYZFull interface specification:
contract/contracts/hello-world/src/interfaces/autoshare.rs