【问题标题】:Why is NEAR `nft_mint` event not emitted?为什么没有发出 NEAR `nft_mint` 事件?
【发布时间】:2022-10-13 00:23:11
【问题描述】:

https://github.com/NEAR-Edu/near-certification-tools/blob/ba220aa6d13b9d8e1996526c796aec203a2853d3/data-contract/src/contract/mint.rs#L41 我打电话给self.tokens.internal_mint(token_id, to_account_id, Some(combined_metadata)) 它打电话给NftMint { owner_id: &token.owner_id, token_ids: &[&token.token_id], memo: None }.emit();

但是当我铸造 NFT 时,我从未在测试网资源管理器中看到 nft_mint 事件。

我做错了什么,或者我如何逐步调试以缩小到出现问题的一般区域?

NFT 确实成功铸造了,因为我的 TypeScript const response = await (contract as NFT).nft_tokens_for_owner({ account_id: accountId }); 找到了它。

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

    使用工作空间 3.2.2 版在 https://github.com/near-examples/NFT 中运行 TypeScript 集成测试将打印智能合约日志,因此标准合约将使用 emit() 发出事件。

    至于这个合约,你可以在项目根目录下创建一个integration-tests 文件夹。在这里,您可以使用工作空间库运行本地版本的 NEAR Blockchain 并将您的智能合约代码上传到其中,然后运行 ​​nft_mint 函数,如下所示:

    import { Worker, NearAccount, tGas, NEAR, BN } from 'near-workspaces';
    import anyTest, { TestFn } from 'ava';
    import { mint_more, nft_total_supply } from './utils';
    
    const test = anyTest as TestFn<{
        worker: Worker;
        accounts: Record<string, NearAccount>;
    }>;
    
    test.beforeEach(async t => {
        const worker = await Worker.init();
        const root = worker.rootAccount;
        const nft = await root.devDeploy(
            '../data-contract/target/wasm32-unknown-unknown/release/near_certification_tools.wasm',
            {
                initialBalance: NEAR.parse('100 N').toJSON(),
                method: "new",
                args: {
                    owner_id: root.accountId,
                    metadata: {
                        spec: "nft-1.0.0",
                        name: "Certification Tools",
                        symbol: "CT",
                        icon: null,
                        base_uri: null,
                        reference: null,
                        reference_hash: null,
                    },
                    options: {
                        can_transfer: true,
                        can_invalidate: true
                    }
                }
            },
        );
    
        const alice = await root.createSubAccount('alice', { initialBalance: NEAR.parse('100 N').toJSON() });
    
        t.context.worker = worker;
        t.context.accounts = { root, alice, nft };
    });
    
    test.afterEach.always(async t => {
        await t.context.worker.tearDown().catch(error => {
            console.log('Failed to tear down the worker:', error);
        });
    });
    
    
    test('Simple mint', async test => {
        const { root, alice, nft } = test.context.accounts;
        await root.call(
            nft, 
            "add_issuer",
            { account_id: root.accountId },
        );
        test.log('Issuer set');
        await root.call(
            nft,
            "nft_mint",
            {
                token_id: "0",
                receiver_account_id: alice.accountId,
                token_metadata: {
                    title: "Olympus Mons",
                    description: "The tallest mountain in the charted solar system",
                    media: null,
                    media_hash: null,
                    copies: 10000,
                    issued_at: null,
                    expires_at: null,
                    starts_at: null,
                    updated_at: null,
                    extra: null,
                    reference: null,
                    reference_hash: null,
                },
                certification_metadata: {
                    authority_name: "NASA",
                    authority_id: null,
                    program: "Mars 2020",
                    program_name: null,
                    program_link: null,
                    program_start_date: null,
                    program_end_date: null,
                    original_recipient_id: null,
                    original_recipient_name: null,
                    valid: true,
                    memo: null
                }
            },
            { attachedDeposit: '8540000000000000000000' }
        );
        test.pass();
    });
    

    这会生成以下输出,从而将EVENT_LOG 发送到合约日志:

    【讨论】:

      猜你喜欢
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      • 2023-03-20
      • 2012-11-17
      • 2011-05-18
      相关资源
      最近更新 更多