-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummon_hero.js
42 lines (41 loc) · 1.06 KB
/
summon_hero.js
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
export async function summonHero({ dappAddress, walletAddress, tokenAddress, tokenId, name, cost }) {
const tokenContract = await Tezos.wallet.at(tokenAddress)
const dappContract = await Tezos.wallet.at(dappAddress)
const batchOp = await Tezos.wallet.batch([
{
kind: OpKind.TRANSACTION,
...tokenContract.methods.update_operators([
{
add_operator: {
owner: walletAddress,
operator: dappAddress,
token_id: tokenId
}
}
]).toTransferParams()
},
{
kind: OpKind.TRANSACTION,
...dappContract.methods.summon_hero(
name,
tokenAddress,
tokenId
).toTransferParams(),
amount: cost
},
{
kind: OpKind.TRANSACTION,
...tokenContract.methods.update_operators([
{
remove_operator: {
owner: walletAddress,
operator: dappAddress,
token_id: tokenId
}
}
]).toTransferParams()
},
])
const batch = await batchOp.send()
await batch.confirmation()
}