Skip to content

Commit 5b98b16

Browse files
authored
add TRC20TransferFrom (#124)
1 parent 5f7c89c commit 5b98b16

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

pkg/client/trc20.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import (
1414
)
1515

1616
const (
17-
trc20TransferMethodSignature = "0xa9059cbb"
18-
trc20ApproveMethodSignature = "0x095ea7b3"
19-
trc20TransferEventSignature = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
20-
trc20NameSignature = "0x06fdde03"
21-
trc20SymbolSignature = "0x95d89b41"
22-
trc20DecimalsSignature = "0x313ce567"
23-
trc20BalanceOf = "0x70a08231"
17+
trc20TransferMethodSignature = "0xa9059cbb"
18+
trc20ApproveMethodSignature = "0x095ea7b3"
19+
trc20TransferEventSignature = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
20+
trc20NameSignature = "0x06fdde03"
21+
trc20SymbolSignature = "0x95d89b41"
22+
trc20DecimalsSignature = "0x313ce567"
23+
trc20BalanceOf = "0x70a08231"
24+
trc20TransferFromMethodSignature = "0x23b872dd"
2425
)
2526

2627
// TRC20Call make cosntant calll
@@ -178,6 +179,26 @@ func (g *GrpcClient) TRC20Send(from, to, contract string, amount *big.Int, feeLi
178179
return g.TRC20Call(from, contract, req, false, feeLimit)
179180
}
180181

182+
/*
183+
parameter:owner is who will sign the tx
184+
*/
185+
func (g *GrpcClient) TRC20TransferFrom(owner, from, to, contract string, amount *big.Int, feeLimit int64) (*api.TransactionExtention, error) {
186+
addrA, err := address.Base58ToAddress(from)
187+
if err != nil {
188+
return nil, err
189+
}
190+
addrB, err := address.Base58ToAddress(to)
191+
if err != nil {
192+
return nil, err
193+
}
194+
ab := common.LeftPadBytes(amount.Bytes(), 32)
195+
req := "0x23b872dd" +
196+
"0000000000000000000000000000000000000000000000000000000000000000"[len(addrA.Hex())-4:] + addrA.Hex()[4:] +
197+
"0000000000000000000000000000000000000000000000000000000000000000"[len(addrB.Hex())-4:] + addrB.Hex()[4:]
198+
req += common.Bytes2Hex(ab)
199+
return g.TRC20Call(owner, contract, req, false, feeLimit)
200+
}
201+
181202
// TRC20Approve approve token to address
182203
func (g *GrpcClient) TRC20Approve(from, to, contract string, amount *big.Int, feeLimit int64) (*api.TransactionExtention, error) {
183204
addrB, err := address.Base58ToAddress(to)

0 commit comments

Comments
 (0)