Skip to content

Commit b90d360

Browse files
gakonstGeorge
andauthored
docs(foundry): add T1 features - 2D nonces, expiring nonces, access keys, sponsors, batching (#55)
Co-authored-by: George <george@tempo.xyz>
1 parent 5f8b04c commit b90d360

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/pages/sdk/foundry/index.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,24 @@ forge script script/Mail.s.sol \
130130
--sender <YOUR_WALLET_ADDRESS> \
131131
--broadcast \
132132
--verify
133+
134+
# Batch multiple calls into a single atomic transaction
135+
forge script script/Deploy.s.sol \
136+
--broadcast --batch \
137+
--rpc-url $TEMPO_RPC_URL \
138+
--private-key $PRIVATE_KEY
133139
```
134140

135141
For more verification options including verifying existing contracts and API verification, see [Contract Verification](/quickstart/verify-contracts).
136142

143+
:::warning[Batch Transaction Rules]
144+
- **Atomic execution**: If any call reverts, the entire batch reverts
145+
- **Single CREATE allowed**: At most one contract deployment per batch
146+
- **CREATE must be first**: Deployment must be the first operation
147+
- **Value must be zero**: Since Tempo has no native token, value must be 0
148+
- **Silent failures**: Calling a non-existent function without a fallback succeeds silently
149+
:::
150+
137151
### Interact & debug with `cast`
138152

139153
```bash
@@ -173,6 +187,61 @@ cast send <CONTRACT_ADDRESS> <FUNCTION_SIGNATURE> \
173187
# Replay a transaction by hash:
174188
cast run <TX_HASH> \
175189
--rpc-url $TEMPO_RPC_URL
190+
191+
# Send a batch transaction with multiple calls:
192+
cast batch-send \
193+
--call "<CONTRACT_ADDRESS>::increment()" \
194+
--call "<CONTRACT_ADDRESS>::setNumber(uint256):500" \
195+
--rpc-url $TEMPO_RPC_URL \
196+
--private-key $PRIVATE_KEY
197+
198+
# Batch with pre-encoded calldata:
199+
ENCODED=$(cast calldata "setNumber(uint256)" 200)
200+
cast batch-send \
201+
--call "<CONTRACT_ADDRESS>::$ENCODED" \
202+
--call "<CONTRACT_ADDRESS>::setNumber(uint256):101" \
203+
--rpc-url $TEMPO_RPC_URL \
204+
--private-key $PRIVATE_KEY
205+
206+
# Sponsored transaction (gasless for sender):
207+
# Step 1: Get the fee payer signature hash
208+
FEE_PAYER_HASH=$(cast mktx <CONTRACT_ADDRESS> 'increment()' \
209+
--rpc-url $TEMPO_RPC_URL \
210+
--private-key $SENDER_KEY \
211+
--print-sponsor-hash)
212+
# Step 2: Sponsor signs the hash
213+
SPONSOR_SIG=$(cast wallet sign --private-key $SPONSOR_KEY "$FEE_PAYER_HASH" --no-hash)
214+
# Step 3: Send with sponsor signature
215+
cast send <CONTRACT_ADDRESS> 'increment()' \
216+
--rpc-url $TEMPO_RPC_URL \
217+
--private-key $SENDER_KEY \
218+
--sponsor-signature "$SPONSOR_SIG"
219+
220+
# Send with 2D nonce (parallel tx submission):
221+
cast send <CONTRACT_ADDRESS> 'increment()' \
222+
--rpc-url $TEMPO_RPC_URL \
223+
--private-key $PRIVATE_KEY \
224+
--nonce 0 --nonce-key 1
225+
226+
# Send with expiring nonce (time-bounded tx, max 30s):
227+
VALID_BEFORE=$(($(date +%s) + 25))
228+
cast send <CONTRACT_ADDRESS> 'increment()' \
229+
--rpc-url $TEMPO_RPC_URL \
230+
--private-key $PRIVATE_KEY \
231+
--expiring-nonce --valid-before $VALID_BEFORE
232+
233+
# Send with access key (delegated signing):
234+
# First authorize the key via Account Keychain precompile
235+
cast send 0xAAAAAAAA00000000000000000000000000000000 \
236+
'authorizeKey(address,uint8,uint64,bool,(address,uint256)[])' \
237+
$ACCESS_KEY_ADDR 0 1893456000 false "[]" \
238+
--rpc-url $TEMPO_RPC_URL \
239+
--private-key $ROOT_PRIVATE_KEY
240+
# Then send using the access key
241+
cast send <CONTRACT_ADDRESS> 'increment()' \
242+
--rpc-url $TEMPO_RPC_URL \
243+
--access-key $ACCESS_KEY_PRIVATE_KEY \
244+
--root-account $ROOT_ADDRESS
176245
```
177246

178247
### Limitations

0 commit comments

Comments
 (0)