-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.ts
More file actions
55 lines (47 loc) · 1.35 KB
/
cli.ts
File metadata and controls
55 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Expiry } from 'accounts'
import { Cli } from 'incur'
import { Hex } from 'ox'
import { parseUnits } from 'viem'
import { connect } from 'viem/experimental/erc7846'
import { Actions } from 'viem/tempo'
import { Provider } from '../../src/cli/index.js'
const provider = Provider.create({
feePayer: 'https://sponsor.moderato.tempo.xyz',
mpp: true,
testnet: true,
})
const token = '0x20c0000000000000000000000000000000000000' as const
Cli.create('example', {
async run() {
const client = provider.getClient()
// 1. Connect Tempo Wallet and authorize an access key with limits + expiry.
await connect(client, {
capabilities: {
authorizeAccessKey: {
expiry: Expiry.days(1),
limits: [
{
limit: Hex.fromNumber(parseUnits('100', 6)),
token,
},
],
},
},
})
// 2. Perform a TIP-20 transfer.
const account = provider.getAccount()
const { receipt } = await Actions.token.transferSync(client, {
account,
amount: parseUnits('1', 6),
to: account.address,
token,
})
// 3. Fetch a paid API endpoint via MPP.
const response = await fetch('https://mpp.dev/api/ping/paid')
const data = await response.text()
return {
hash: receipt.transactionHash,
ping: data,
}
},
}).serve()