forked from tzConnectBerlin/peppermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug-contract.mjs
145 lines (122 loc) · 5.43 KB
/
debug-contract.mjs
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
import { createRequire } from 'module'
import { MichelsonMap, TezosToolkit, compose } from '@taquito/taquito'
import { InMemorySigner } from '@taquito/signer'
import { char2Bytes, bytes2Char, verifySignature } from '@taquito/utils'
import { Tzip12Module, tzip12 } from '@taquito/tzip12'
import { tzip16 } from '@taquito/tzip16'
const require = createRequire(import.meta.url)
require('console-stamp')(console)
const config = require('./config.json')
const creatorPrivateKey = process.env.CREATOR_PRIVATE_KEY
|| 'edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq'
const rpcUrl = process.env.RPC_URL || 'https://jakartanet.ecadinfra.com'
const main = async function() {
const tezos = new TezosToolkit(rpcUrl)
tezos.addExtension(new Tzip12Module())
const signer = new InMemorySigner(creatorPrivateKey)
const address = await signer.publicKeyHash()
const pk = await signer.publicKey()
console.log('Signer initialized for originating address', address)
console.log('Signer initialized for originating pk', pk)
tezos.setSignerProvider(signer)
// const bytes = char2Bytes(JSON.stringify({
// "handler": "nft-asset",
// "name": "mint_tokens",
// "args": {
// "token_id": 2,
// "metadata_uri": "ipfs://QmPxz1s3wYVGibvLpgcqFMrvtnhVmNU5Y7xo9qLGLAGeHx",
// "owners": ["tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb"]
// }
// }))
// signer.sign(bytes).then(signature => {
// console.log('bytes', bytes)
// console.log('sig', signature.sig)
// const verified = verifySignature(bytes, pk, signature.sig)
// console.log('Message verified?', verified)
// }).catch(err => console.error('err!', err))
const tokenId = 1
tezos.contract
// .at(config.nftContract)
// .at('KT1HcpvkvqaqzbTfz4mS6Ldwn31vVhzjwf8q') // has contract metadata
.at('KT1E44qQrEEyMmczvqsuFopdrFRKrM2G7eLw')
.then(contract => {
const schema = contract.parameterSchema.ExtractSchema()
console.log('CONTRACT PARAMETER SCHEMA\n', JSON.stringify(schema, null, 2))
console.log(`Fetching the token metadata for the token ID ${tokenId}...`)
return contract.storage()
})
.then(storage => {
console.log('storage', JSON.stringify(storage, null, 2))
// return storage.metadata.get('content') // contract metadata
// return storage.assets.ledger.get(tokenId) // owner of tokenId
return storage.assets.metadata.metadata.get({ from_: tokenId, to_: tokenId + 1 })
})
.then(metadata => {
// console.log('metadata', JSON.stringify(bytes2Char(metadata), null, 2))
// console.log('metadata', bytes2Char(metadata))
console.log('metadata', metadata)
return metadata.token_info.get('')
})
.then(token_info => {
console.log('token_info', bytes2Char(token_info))
})
// .then(contract => {
// const methods = contract.parameterSchema.ExtractSignatures()
// const schema = contract.parameterSchema.ExtractSchema()
// console.log('METHODS?', contract.methods)
// console.log('CONTRACT PARAMETER SCHEMA\n', JSON.stringify(schema, null, 2))
// // console.log('CONTRACT METHOD SIGNATURES\n', JSON.stringify(methods, null, 2))
// // console.log('contract.mint_tokens()', JSON.stringify(contract.methods.mint_tokens().getSignature(), null, 2))
// // console.log('contract.tokens()', JSON.stringify(contract.methods.tokens().getSignature(), null, 2))
// console.log('contract.assets()', JSON.stringify(contract.methods.assets().getSignature(), null, 2))
// })
// .then(contract => {
// // token_metadata = {
// // "token_id": 0,
// // "token_info": {
// // "0": "left".encode().hex(),
// // "1": "right".encode().hex(),
// // "decimals": "0".encode().hex(),
// // "name": "socks token".encode().hex(),
// // "symbol": "SOCK".encode().hex(),
// // },
// // self.fa2.mint_tokens(
// // {
// // "metadata": token_metadata,
// // "token_def": {
// // "from_": 0,
// // "to_": 2,
// // },
// // "owners": [owner1_address, owner2_address],
// // }
// // let token_info = MichelsonMap.fromLiteral({"": char2Bytes(metadata_ipfs)})
// const uri = 'ipfs://QmPxz1s3wYVGibvLpgcqFMrvtnhVmNU5Y7xo9qLGLAGeHx'
// const token_id = 1
// const from_ = token_id
// const to_ = token_id + 1
// const token_info = MichelsonMap.fromLiteral({ '': char2Bytes(uri) })
// const owners = ['tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb']
// // console.log('mint_tokens func', JSON.stringify(contract.methods.mint_tokens().getSignature(), null, 2))
// // (from_, to_, token_id, token_info, owners)
// return contract.methods.mint_tokens(from_, to_, token_id, token_info, owners).send()
// })
// .then(op => {
// console.log(`Waiting for ${op.hash} to be confirmed`)
// return op.confirmation(config.confirmations).then(() => op.hash)
// })
// .then(hash => {
// console.log(`Confirmed op ${hash}`)
// })
.catch(error => console.error(error))
}
main()
.then(() => {
console.log('Done')
})
.catch((err) => {
console.error('An error has ocurred deploying contract\n', err)
})
// [15.06.2022 21:04.25.658] [LOG] Signer initialized for originating address tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
// [15.06.2022 21:04.25.671] [LOG] Done
// [15.06.2022 21:04.25.745] [LOG] Waiting for ookNRsyUJN2U854znNdKzF2UJ2PmVgqGJjhtToe5z5uR794RUE4 to be confirmed
// [15.06.2022 21:04.30.761] [LOG] Confirmed op ookNRsyUJN2U854znNdKzF2UJ2PmVgqGJjhtToe5z5uR794RUE4