(tick: string, toAddresses: ISendToAddress[])
| 387 | |
| 388 | // Transfer N20 contract Token |
| 389 | async sendTokenToMultiAddresses(tick: string, toAddresses: ISendToAddress[]) { |
| 390 | const tokenAmounts: bigint[] = []; |
| 391 | const tokenAddresses: ISendToAddress[] = []; |
| 392 | // Get Token UTXOs |
| 393 | const tokenUtxos = await await this.getTokenUtxos(tick); |
| 394 | const balance = tokenUtxos.reduce( |
| 395 | (acc: bigint, cur: ITokenUtxo) => acc + BigInt(cur.amount), |
| 396 | 0n |
| 397 | ); |
| 398 | let total = 0n; |
| 399 | for (let i = 0; i < toAddresses.length; i++) { |
| 400 | const amt = BigInt(toAddresses[i]!.amount); |
| 401 | total += amt; |
| 402 | tokenAmounts.push(amt); |
| 403 | tokenAddresses.push({ |
| 404 | address: toAddresses[i]!.address, |
| 405 | amount: MIN_SATOSHIS, |
| 406 | }); |
| 407 | } |
| 408 | |
| 409 | if (balance < total) { |
| 410 | throw new Error("Insufficient balance"); |
| 411 | } |
| 412 | |
| 413 | if (balance > BigInt(total)) { |
| 414 | tokenAddresses.push({ |
| 415 | address: this.currentAccount.tokenAddress!.address!, |
| 416 | amount: MIN_SATOSHIS, |
| 417 | }); |
| 418 | } |
| 419 | const transferData: ITransferN20Data = { |
| 420 | p: "n20", |
| 421 | op: "transfer", |
| 422 | tick, |
| 423 | amt: tokenAmounts, |
| 424 | }; |
| 425 | |
| 426 | const tx = await this.buildNoteTransaction( |
| 427 | buildNotePayload(transferData), |
| 428 | tokenAddresses, |
| 429 | tokenUtxos |
| 430 | ); |
| 431 | const result = await this.broadcastTransaction(tx); |
| 432 | |
| 433 | return { |
| 434 | transferData, |
| 435 | result, |
| 436 | }; |
| 437 | } |
| 438 | |
| 439 | async tokenList() { |
| 440 | const results = await this.urchain.tokenList( |
nothing calls this directly
no test coverage detected