Last active
September 29, 2022 21:38
-
-
Save bijoutrouvaille/2ba57dae5e25734c95f4907a1663a20c to your computer and use it in GitHub Desktop.
Taquito calling an fa2 endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as t from "@taquito/taquito"; | |
import * as s from "@taquito/signer"; | |
import * as c from '@taquito/michel-codec'; | |
import * as fs from 'fs'; | |
async function main() { | |
const secretKeys = JSON.parse(fs.readFileSync(process.env['HOME'] + '/.tezos-client/secret_keys', 'utf-8')) as {name: string, value: string}[]; | |
const test_nft_contract_address = 'KT1PZmifjt6kGBLK5ybXjEbMh1CHyqspY5ef'; | |
const jeff = ("tz1aYtkBNrE111VBAynvEbDdcs2wnz71p42G") | |
const alice = ("tz1VQbvfgtQXMdqH9fcx82n4mxNc3wi5spS1") | |
const bob = ("tz1fWXnqim6ceTxtKATSny9N2Uei9KEDTcAU") | |
const packToBytes = (string: string): Uint8Array => | |
(c.packDataBytes({string: string}, {prim: 'bytes'}).bytes) as unknown as Uint8Array; | |
const adminSecretKey = secretKeys.find((k) => k.name == 'jeff') | |
.value.replace('unencrypted:', ''); | |
// const Tezos = new t.TezosToolkit(`https://ghostnet.tezos.marigold.dev/`); | |
const Tezos = new t.TezosToolkit(`https://rpc.ghostnet.teztnets.xyz`); | |
Tezos.setProvider({ | |
config: {defaultConfirmationCount: 1, confirmationPollingTimeoutSecond: 60*5}, | |
protocol: t.Protocols.PtKathman, | |
rpc: `https://rpc.ghostnet.teztnets.xyz`, | |
signer: new s.InMemorySigner( adminSecretKey ) | |
}); | |
const contract = await Tezos.contract.at<t.ContractAbstraction<t.ContractProvider>>(test_nft_contract_address); | |
const metadata = new t.MichelsonMap<string, Uint8Array>(); | |
const artworkURL = 'https://abc.xyz'; | |
metadata.set('', packToBytes(artworkURL)); | |
const token_id = 1; | |
const mintTransferParams = await contract.methods | |
.mint([{address: alice, amount: 1, token_id: token_id, metadata: metadata}]) | |
.toTransferParams({gasLimit: 10000, amount: 100, mutez: true, fee: 1000}); | |
const est = await Tezos.estimate.transfer(mintTransferParams); | |
const r1 = await Tezos.contract.transfer(mintTransferParams); | |
console.log('transaction estimates', objex(est, 'totalCost', 'suggestedFeeMutez', 'consumedMilligas', 'burnFeeMutez')); | |
console.log('results') | |
console.dir(r1.results, {depth: 111}); | |
console.log('waiting confirmtion') | |
const conf = await r1.confirmation(1) | |
console.log('confirmed', conf) | |
} | |
main().catch(e => { | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output for console.dir(r1.results, {depth: 111});