使用JavaScript对create方法进行测试

1- 进入Js
https://polkadot.js.org/apps/#/js

使用JavaScript对create方法进行测试_第1张图片
image.png

2-找到transfer


使用JavaScript对create方法进行测试_第2张图片
image.png
// All code is wrapped within an async closure,
// allowing access to api, hashing, keyring, types, util.
// (async ({ api, hashing, keyring, types, util }) => {
//   ... any user code is executed here ...
// })();

// Make a transfer from Alice to Bob and listen to system events.
// You need to be connected to a development chain for this example to work.
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';

// Get a random number between 1 and 100000
const randomAmount = Math.floor((Math.random() * 100000) + 1);

// Create a extrinsic, transferring randomAmount units to Bob.
const transfer = api.tx.balances.transfer(BOB, randomAmount);

// Sign and Send the transaction
transfer.signAndSend(ALICE, ({ events = [], status }) => {
  if (status.isFinalized) {
    console.log('Successful transfer of ' + randomAmount + ' with hash ' + status.asFinalized.toHex());
  } else {
    console.log('Status of transfer: ' + status.type);
  }

  events.forEach(({ phase, event: { data, method, section } }) => {
    console.log(phase.toString() + ' : ' + section + '.' + method + ' ' + data.toString());
  });
});

3-Create测试代码

const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';

const transfer = api.tx.kitties.create();

transfer.signAndSend(ALICE, ({ events = [], status }) => {
  if (status.isFinalized) {
    console.log('Successful transfer of ' + randomAmount + ' with hash ' + status.asFinalized.toHex());
  } else {
    console.log('Status of transfer: ' + status.type);
  }

  events.forEach(({ phase, event: { data, method, section } }) => {
    console.log(phase.toString() + ' : ' + section + '.' + method + ' ' + data.toString());
  });
}

测试的Js可能有问题,一直通过不了;;;
可能的原因是需要本地启动Js;应用程序;针对这样的想法还没有进行测试,先留个记录吧,担心以后会忘记,

声明:本文由River进行整理和编译,为原创作品,转载请注明出处,多谢;

你可能感兴趣的:(使用JavaScript对create方法进行测试)