-
Notifications
You must be signed in to change notification settings - Fork 32
/
NftItem.ts
51 lines (45 loc) · 2.24 KB
/
NftItem.ts
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
import {Address, beginCell, Cell, Contract, ContractProvider, Sender, toNano, Builder, StateInit} from "@ton/core";
export type NftItemData = {
inited: boolean
index: number
collection: Address | null
owner: Address | null
content: Cell | null
}
export class NftItem implements Contract {
static readonly code = Cell.fromBase64('te6ccgECDgEAAdwAART/APSkE/S88sgLAQIBYgIDAgLOBAUACaEfn+AFAgEgBgcCASAMDQLPDIhxwCSXwPg0NMDAXGwkl8D4PpA+kAx+gAxcdch+gAx+gAwc6m0APACBLOOFDBsIjRSMscF8uGVAfpA1DAQI/AD4AbTH9M/ghBfzD0UUjC64wIwNDQ1NYIQL8smohK64wJfBIQP8vCAICQARPpEMHC68uFNgAqwyEDdeMkATUTXHBfLhkfpAIfAB+kDSADH6ACDXScIA8uLEggr68IAboSGUUxWgod4i1wsBwwAgkgahkTbiIML/8uGSIZQQKjdb4w0CkzAyNOMNVQLwAwoLAHJwghCLdxc1BcjL/1AEzxYQJIBAcIAQyMsFUAfPFlAF+gIVy2oSyx/LPyJus5RYzxcBkTLiAckB+wAAfIIQBRONkchQCc8WUAvPFnEkSRRURqBwgBDIywVQB88WUAX6AhXLahLLH8s/Im6zlFjPFwGRMuIByQH7ABBHAGom8AGCENUydtsQN0QAbXFwgBDIywVQB88WUAX6AhXLahLLH8s/Im6zlFjPFwGRMuIByQH7AAA7O1E0NM/+kAg10nCAJp/AfpA1DAQJBAj4DBwWW1tgAB0A8jLP1jPFgHPFszJ7VSA=')
constructor(readonly address: Address, readonly init?: StateInit) {}
static createFromAddress(address: Address) {
return new NftItem(address);
}
async sendTransfer(provider: ContractProvider, via: Sender, params: {
value?: bigint
to: Address
responseTo?: Address
forwardAmount?: bigint
forwardBody?: Cell | Builder
}) {
await provider.internal(via, {
value: params.value ?? toNano('0.05'),
body: beginCell()
.storeUint(0x5fcc3d14, 32) // op
.storeUint(0, 64) // query id
.storeAddress(params.to)
.storeAddress(params.responseTo)
.storeBit(false) // custom payload
.storeCoins(params.forwardAmount ?? 0n)
.storeMaybeRef(params.forwardBody)
.endCell()
})
}
async getData(provider: ContractProvider): Promise<NftItemData> {
const { stack } = await provider.get('get_nft_data', [])
return {
inited: stack.readBoolean(),
index: stack.readNumber(),
collection: stack.readAddressOpt(),
owner: stack.readAddressOpt(),
content: stack.readCellOpt(),
}
}
}