-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOrderCollection.ts
More file actions
41 lines (35 loc) · 1.35 KB
/
OrderCollection.ts
File metadata and controls
41 lines (35 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
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from 'ton-core';
export type OrderCollectionConfig = {
ownerAddress: Address;
nextItemIndex: number;
content: Cell;
nftItemCode: Cell;
royaltyParams: Cell;
};
export function orderCollectionConfigToCell(config: OrderCollectionConfig): Cell {
return beginCell()
.storeAddress(config.ownerAddress)
.storeUint(config.nextItemIndex, 64)
.storeRef(config.content)
.storeRef(config.nftItemCode)
.storeRef(config.royaltyParams)
.endCell();
}
export class OrderCollection implements Contract {
constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {}
static createFromAddress(address: Address) {
return new OrderCollection(address);
}
static createFromConfig(config: OrderCollectionConfig, code: Cell, workchain = 0) {
const data = orderCollectionConfigToCell(config);
const init = { code, data };
return new OrderCollection(contractAddress(workchain, init), init);
}
async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
await provider.internal(via, {
value,
sendMode: SendMode.PAY_GAS_SEPARATLY,
body: beginCell().endCell(),
});
}
}