Stellar Smart Contract Auction
How to make a bid on a
Stellar Smart Contract Auction
We will come back to the actual Rust (Soroban SDK) auction code – the lib.rs – but while I have it to hand let’s just cover how to deploy, invoke AND make a bid on this toy auction smart contract.
The key thing to know, is that you need to fund your bidder account (aka bob in this case)
If you are doing this for the first time, create “alice” and “bob” and then fund bob using his public address.
Create a Keypair (or show keys if you already have a keypair)
stellar keys generate --rpc-url https://horizon-testnet.stellar.org --network-passphrase "Test SDF Network ; September 2015" --network testnet alice
> stellar keys address alice
GAFBM3TQNO6QY55XIU2D4SDV2X4UR2BYFIHLBNQNMXSOPFCDAOXDCWTL
> stellar keys address bob
GBLQILJMLG65EFPKRPEUR2FMH3VEX23BYEV6ZHBO3ORTO6L7Y6LTSANS
Fund the user’s account!
Funding with “friendbot”
If you want to make a bid you need to have some “test” lumens (Stellar currency)
Use bob’s address, so bob has funds to make a bid on alice’s auction
curl 'https://friendbot.stellar.org?addr=GCJIE7EIKWRMPZOW3OPGYJHQO6E6F5OZVQQNLFJGB7PAHVBS5KBQEUFM'
Deploy, invoke, make a bid!
stellar contract deploy --source-account alice --network testnet --wasm ../../target/wasm32-unknown-unknown/release/auction.wasm
> stellar contract deploy --source-account alice --network testnet --wasm target/wasm32-unknown-unknown/release/auction.wasm
ℹ️ Skipping install because wasm already installed
ℹ️ Using wasm hash 0647ce131fa2a2145a525f56a4cd192dffa8b96c740cd2161118982e44a6088e
ℹ️ Simulating deploy transaction…
🌎 Submitting deploy transaction…
ℹ️ Transaction hash is 07a09ff9af4f63d0abfdca7cf8774a6a17da6b3633102199bf9bb83b9c7379a4
🔗 https://stellar.expert/explorer/testnet/tx/07a09ff9af4f63d0abfdca7cf8774a6a17da6b3633102199bf9bb83b9c7379a4
ℹ️ Signing transaction: 07a09ff9af4f63d0abfdca7cf8774a6a17da6b3633102199bf9bb83b9c7379a4
🔗 https://stellar.expert/explorer/testnet/contract/CBRNLHZNAZU3DSN6Z4J2BQBTSKAQVNU2BR55AWK737LAMDUCQ2ZSJOTC
✅ Deployed!
stellar contract invoke \
--id CBRNLHZNAZU3DSN6Z4J2BQBTSKAQVNU2BR55AWK737LAMDUCQ2ZSJOTC \
--source-account alice \
--network testnet \
-- initialize \
--item Snooker_Cue \
--owner alice \
--starting_bid 100 \
--duration 100000
ℹ️ Signing transaction: 31ccee50c7df8e3a474721c858d094b9ae8b976c3818aad9c723cab5ea8bd473
null
stellar contract invoke \
--id CBRNLHZNAZU3DSN6Z4J2BQBTSKAQVNU2BR55AWK737LAMDUCQ2ZSJOTC \
--source-account bob \
--network testnet \
-- bid \
--bidder bob \
--amount 200
stellar contract invoke \
--id CD7VWWQS6IWQZR3YZMUDZNFJBIGRZ4ESUXICPDUDB2J4PPKOIGII3MFE \
--source-account bob \
--network testnet \
-- bid \
--bidder bob \
--amount 300
bob has made a successful bid of 300!
remember the duration is in seconds, so if you’re testing for a few hours, set the auction duration for 3600 * 8 or something like that yeah?
ps. I find chatGPT very hand for formatting the commands and args for stellar-cli don’t be afraid to use it ! 😊
To check the balance of an account you need the native asset ID :
> stellar contract id asset --asset native --network testnet
CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC
make sure you fund your users!
stellar keys address eddie
GCPL7QLBF47V3PFVTUEKHZII7NT2BD7ZMJP4HTE64VK6QQTKHJEMLTIL
curl 'https://friendbot.stellar.org?addr=GCPL7QLBF47V3PFVTUEKHZII7NT2BD7ZMJP4HTE64VK6QQTKHJEMLTIL'
{
"_links": {
"self": {
"href": "https://horizon-testnet.stellar.org/transactions/b145a74805a32681e6c0697e636628bcc429416ba5989dd26fd5a5e099467470"
},
"account": {
"href": "https://horizon-testnet.stellar.org/accounts/GCTRJAQWFO2D6LFEYGQNLNVBLRAIBFQ7AYQROSL7CITLVSYWF6ORLDES"
},
"ledger": {
"href": "https://horizon-testnet.stellar.org/ledgers/584211"
},
"operations": {
"href": "https://horizon-testnet.stellar.org/transactions/b145a74805a32681e6c0697e636628bcc429416ba5989dd26fd5a5e099467470/operations{?cursor,limit,order}",
"templated": true
},
"effects": {
"href": "https://horizon-testnet.stellar.org/transactions/b145a74805a32681e6c0697e636628bcc429416ba5989dd26fd5a5e099467470/effects{?cursor,limit,order}",
"templated": true
},
"precedes": {
"href": "https://horizon-testnet.stellar.org/transactions?order=asc\u0026cursor=2509167138967552"
},
"succeeds": {
"href": "https://horizon-testnet.stellar.org/transactions?order=desc\u0026cursor=2509167138967552"
},
"transaction": {
"href": "https://horizon-testnet.stellar.org/transactions/b145a74805a32681e6c0697e636628bcc429416ba5989dd26fd5a5e099467470"
}
},
"id": "b145a74805a32681e6c0697e636628bcc429416ba5989dd26fd5a5e099467470",
"paging_token": "2509167138967552",
"successful": true,
"hash": "b145a74805a32681e6c0697e636628bcc429416ba5989dd26fd5a5e099467470",
"ledger": 584211,
"created_at": "2025-01-13T13:30:48Z",
"source_account": "GCTRJAQWFO2D6LFEYGQNLNVBLRAIBFQ7AYQROSL7CITLVSYWF6ORLDES",
"source_account_sequence": "1103806595172",
"fee_account": "GCTRJAQWFO2D6LFEYGQNLNVBLRAIBFQ7AYQROSL7CITLVSYWF6ORLDES",
"fee_charged": "100",
"max_fee": "1000000",
"operation_count": 1,
"envelope_xdr": "AAAAAgAAAACnFIIWK7Q/LKTBoNW2oVxAgJYfBiEXSX8SJrrLFi+dFQAPQkAAAAEBAAAAZAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAABB90WssODNIgi6BHveqzxTRmIpvAFRyVNM+Hm2GVuCcAAAAAAAAAACev8FhLz9dvLWdCKPlCPtnoI/5Yl/DzJ7lVehCajpIxQAAABdIdugAAAAAAAAAAAIWL50VAAAAQKuhXfKVVRN4J/DMnNMX0nQincE4WK2Er4ZUunGKodWff3kvTExgTvx3p7S53fDDa5qqLPXk/dPVTK8kxDGvfACGVuCcAAAAQN4/0AIImJAzYD7bwvDcFWWcBmM5nJFlGg0h589RY3kk2tc6H5QvL82D8w8LOueMYZBxYxZ05S5XdLdSkzaW+Aw=",
"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA=",
"fee_meta_xdr": "AAAAAgAAAAMACN56AAAAAAAAAACnFIIWK7Q/LKTBoNW2oVxAgJYfBiEXSX8SJrrLFi+dFQAAAAA8MznUAAABAQAAAGMAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAADAAAAAAAI3noAAAAAZ4TbfAAAAAAAAAABAAjqEwAAAAAAAAAApxSCFiu0PyykwaDVtqFcQICWHwYhF0l/Eia6yxYvnRUAAAAAPDM5cAAAAQEAAABjAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAwAAAAAACN56AAAAAGeE23wAAAAA",
"memo_type": "none",
"signatures": [
"q6Fd8pVVE3gn8Myc0xfSdCKdwThYrYSvhlS6cYqh1Z9/eS9MTGBO/HentLnd8MNrmqos9eT909VMryTEMa98AA==",
"3j/QAgiYkDNgPtvC8NwVZZwGYzmckWUaDSHnz1FjeSTa1zoflC8vzYPzDws654xhkHFjFnTlLld0t1KTNpb4DA=="
],
"preconditions": {
"timebounds": {
"min_time": "0"
}
}
}% > stellar contract invoke \
--id CBHUAEGERQHNYDPULSD7XZ72NXNWNOUTB2IMMFAXRXE4BFNVZLVRQB4H \
--source-account eddie \
--network testnet \
-- bid \
--bidder eddie \
--amount 200
ℹ️ Signing transaction: f7a92f54aede97021a63c5a44a610eb97f3bb5227a8ef9415d5ff4a65f1beca8
Also notice the error in the diagnostics if the bid does not surpass the previous amount?