Skip to content

Instantly share code, notes, and snippets.

@bijoutrouvaille
Last active September 29, 2022 21:38
Show Gist options
  • Save bijoutrouvaille/2ba57dae5e25734c95f4907a1663a20c to your computer and use it in GitHub Desktop.
Save bijoutrouvaille/2ba57dae5e25734c95f4907a1663a20c to your computer and use it in GitHub Desktop.
Taquito calling an fa2 endpoint
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);
});
@bijoutrouvaille
Copy link
Author

bijoutrouvaille commented Sep 29, 2022

output for console.dir(r1.results, {depth: 111});

[
  {
    kind: 'transaction',
    source: 'tz1aYtkBNrE111VBAynvEbDdcs2wnz71p42G',
    fee: '1000',
    counter: '11973680',
    gas_limit: '10000',
    storage_limit: '199',
    amount: '100',
    destination: 'KT1PZmifjt6kGBLK5ybXjEbMh1CHyqspY5ef',
    parameters: {
      entrypoint: 'mint',
      value: [
        {
          prim: 'Pair',
          args: [
            { int: '1' },
            {
              prim: 'Pair',
              args: [
                { int: '1' },
                {
                  prim: 'Pair',
                  args: [
                    { string: 'tz1VQbvfgtQXMdqH9fcx82n4mxNc3wi5spS1' },
                    [
                      {
                        prim: 'Elt',
                        args: [
                          { string: '' },
                          {
                            bytes: '05010000000f68747470733a2f2f6162632e78797a'
                          }
                        ]
                      }
                    ]
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    metadata: {
      balance_updates: [
        {
          kind: 'contract',
          contract: 'tz1aYtkBNrE111VBAynvEbDdcs2wnz71p42G',
          change: '-1000',
          origin: 'block'
        },
        {
          kind: 'accumulator',
          category: 'block fees',
          change: '1000',
          origin: 'block'
        }
      ],
      operation_result: {
        status: 'applied',
        storage: {
          prim: 'Pair',
          args: [
            {
              prim: 'Pair',
              args: [
                {
                  prim: 'Pair',
                  args: [
                    {
                      bytes: '0000a3912c454b9eaaf1a62db2f324e0bb58db188953'
                    },
                    { int: '178767' }
                  ]
                },
                {
                  prim: 'Pair',
                  args: [ { int: '15' }, { int: '178768' } ]
                }
              ]
            },
            { prim: 'Pair', args: [ { int: '2' }, { int: '178769' } ] }
          ]
        },
        balance_updates: [
          {
            kind: 'contract',
            contract: 'tz1aYtkBNrE111VBAynvEbDdcs2wnz71p42G',
            change: '-49750',
            origin: 'block'
          },
          {
            kind: 'burned',
            category: 'storage fees',
            change: '49750',
            origin: 'block'
          },
          {
            kind: 'contract',
            contract: 'tz1aYtkBNrE111VBAynvEbDdcs2wnz71p42G',
            change: '-100',
            origin: 'block'
          },
          {
            kind: 'contract',
            contract: 'KT1PZmifjt6kGBLK5ybXjEbMh1CHyqspY5ef',
            change: '100',
            origin: 'block'
          }
        ],
        consumed_milligas: '1930202',
        storage_size: '2850',
        paid_storage_size_diff: '199',
        lazy_storage_diff: [
          {
            kind: 'big_map',
            id: '178769',
            diff: {
              action: 'update',
              updates: [
                {
                  key_hash: 'expru2dKqDfZG8hu4wNGkiyunvq2hdSKuVYtcKta7BWP6Q18oNxKjS',
                  key: { int: '1' },
                  value: {
                    prim: 'Pair',
                    args: [
                      { int: '1' },
                      [
                        {
                          prim: 'Elt',
                          args: [
                            { string: '' },
                            {
                              bytes: '05010000000f68747470733a2f2f6162632e78797a'
                            }
                          ]
                        }
                      ]
                    ]
                  }
                }
              ]
            }
          },
          {
            kind: 'big_map',
            id: '178768',
            diff: { action: 'update', updates: [] }
          },
          {
            kind: 'big_map',
            id: '178767',
            diff: {
              action: 'update',
              updates: [
                {
                  key_hash: 'expru2dKqDfZG8hu4wNGkiyunvq2hdSKuVYtcKta7BWP6Q18oNxKjS',
                  key: { int: '1' },
                  value: {
                    bytes: '00006b272d276c89a36efbfbb7694d93fdd88d0cc48f'
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment