forked from thirdweb-dev/go-sdk
/
edition.go
175 lines (160 loc) · 5.05 KB
/
edition.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package thirdweb
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/qnfnypen/thirdweb-go-sdk/v2/abi"
)
// You can access the Edition interface from the SDK as follows:
//
// import (
// "github.com/qnfnypen/thirdweb-go-sdk/v2/thirdweb"
// )
//
// privateKey = "..."
//
// sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
// PrivateKey: privateKey,
// })
//
// contract, err := sdk.GetEdition("{{contract_address}}")
type Edition struct {
*ERC1155Standard
abi *abi.TokenERC1155
Helper *contractHelper
Signature *ERC1155SignatureMinting
Encoder *ContractEncoder
Events *ContractEvents
}
func newEdition(provider *ethclient.Client, address common.Address, privateKey string, storage storage) (*Edition, error) {
if contractAbi, err := abi.NewTokenERC1155(address, provider); err != nil {
return nil, err
} else {
if helper, err := newContractHelper(address, provider, privateKey); err != nil {
return nil, err
} else {
erc1155, err := newERC1155Standard(provider, address, privateKey, storage)
if err != nil {
return nil, err
}
signature, err := newERC1155SignatureMinting(provider, address, privateKey, storage)
if err != nil {
return nil, err
}
encoder, err := newContractEncoder(abi.TokenERC1155ABI, helper)
if err != nil {
return nil, err
}
events, err := newContractEvents(abi.TokenERC1155ABI, helper)
if err != nil {
return nil, err
}
edition := &Edition{
erc1155,
contractAbi,
helper,
signature,
encoder,
events,
}
return edition, nil
}
}
}
// Mint an NFT to the connected wallet.
//
// metadataWithSupply: nft metadata with supply of the NFT to mint
//
// returns: the transaction receipt of the mint
func (edition *Edition) Mint(ctx context.Context, metadataWithSupply *EditionMetadataInput) (*types.Transaction, error) {
return edition.erc1155.Mint(ctx, metadataWithSupply)
}
// Mint a new NFT to the specified wallet.
//
// address: the wallet address to mint the NFT to
//
// metadataWithSupply: nft metadata with supply of the NFT to mint
//
// returns: the transaction receipt of the mint
//
// Example
//
// image, err := os.Open("path/to/image.jpg")
// defer image.Close()
//
// metadataWithSupply := &thirdweb.EditionMetadataInput{
// context.Background(),
// Metadata: &thirdweb.NFTMetadataInput{
// Name: "Cool NFT",
// Description: "This is a cool NFT",
// Image: image,
// },
// Supply: 100,
// }
//
// tx, err := contract.MintTo(context.Background(), "{{wallet_address}}", metadataWithSupply)
func (edition *Edition) MintTo(ctx context.Context, address string, metadataWithSupply *EditionMetadataInput) (*types.Transaction, error) {
return edition.erc1155.MintTo(ctx, address, metadataWithSupply)
}
// Mint additionaly supply of a token to the connected wallet.
//
// tokenId: token ID to mint additional supply of
//
// additionalSupply: additional supply to mint
//
// returns: the transaction receipt of the mint
func (edition *Edition) MintAdditionalSupply(ctx context.Context, tokenId int, additionalSupply int) (*types.Transaction, error) {
return edition.erc1155.MintAdditionalSupply(ctx, tokenId, additionalSupply)
}
// Mint additional supply of a token to the specified wallet.
//
// to: address of the wallet to mint NFTs to
//
// tokenId: token Id to mint additional supply of
//
// additionalySupply: additional supply to mint
//
// returns: the transaction receipt of the mint
func (edition *Edition) MintAdditionalSupplyTo(ctx context.Context, to string, tokenId int, additionalSupply int) (*types.Transaction, error) {
return edition.erc1155.MintAdditionalSupplyTo(ctx, to, tokenId, additionalSupply)
}
// Mint a batch of NFTs to the connected wallet.
//
// metadatasWithSupply: list of NFT metadatas with supplies to mint
//
// returns: the transaction receipt of the mint
func (edition *Edition) MintBatch(ctx context.Context, metadatasWithSupply []*EditionMetadataInput) (*types.Transaction, error) {
return edition.erc1155.MintBatch(ctx, metadatasWithSupply)
}
// Mint a batch of NFTs to a specific wallet.
//
// to: address of the wallet to mint NFTs to
//
// metadatasWithSupply: list of NFT metadatas with supplies to mint
//
// returns: the transaction receipt of the mint
//
// Example
//
// metadatasWithSupply := []*thirdweb.EditionMetadataInput{
// &thirdweb.EditionMetadataInput{
// Metadata: &thirdweb.NFTMetadataInput{
// Name: "Cool NFT",
// Description: "This is a cool NFT",
// },
// Supply: 100,
// },
// &thirdweb.EditionMetadataInput{
// Metadata: &thirdweb.NFTMetadataInput{
// Name: "Cool NFT",
// Description: "This is a cool NFT",
// },
// Supply: 100,
// },
// }
//
// tx, err := contract.MintBatchTo(context.Background(), "{{wallet_address}}", metadatasWithSupply)
func (edition *Edition) MintBatchTo(ctx context.Context, to string, metadatasWithSupply []*EditionMetadataInput) (*types.Transaction, error) {
return edition.erc1155.MintBatchTo(ctx, to, metadatasWithSupply)
}