简体   繁体   中英

How to send spl-tokens with Solana smart contract?

I'm a beginner Rust/Solana Developer and wanted to ask if someone knows how to send a spl-token from an account when the account receives a SOL?

I read the https://docs.solana.com/ but i could not find anything about SPL transfers.

Example of Smart Contract: https://github.com/solana-labs/example-helloworld

Example:

Acc1 sends 0.1 SOL to a address and for that Acc1 receives 1 SPL-TOKEN from that address.

Simple explanation: I need a minting website for a token.

I would really appreciate some help, thanks!

You can send SPL-Tokens by using CPI on the token program's transfer instruction.

For example:

spl_token::instruction::transfer(
  token_program.key,
  source.key,
  destination.key,
  authority.key,
  &[],
  amount,
)?;
invoke_signed(
  &ix,
  &[source, destination, authority, token_program],
  signers,
)

You can find a more in depth example by looking at how the token-swap program uses CPI to transfer spl-tokens

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM