-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d777e1
commit ec98ca3
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package eth | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/coming-chat/wallet-SDK/core/base" | ||
) | ||
|
||
func (c *Chain) TransferNFT(sender, receiver string, nft *base.NFT) (*Transaction, error) { | ||
return c.TransferNFTParams(sender, receiver, nft.Id, nft.ContractAddress, nft.Standard) | ||
} | ||
|
||
// TransferNFTParams | ||
// - param nftStandard: only support erc-721 now, else throw error unsupported nft type. | ||
func (c *Chain) TransferNFTParams(sender, receiver, nftId, nftContractAddress, nftStandard string) (txn *Transaction, err error) { | ||
defer base.CatchPanicAndMapToBasicError(&err) | ||
|
||
if strings.ToLower(nftStandard) != "erc-721" { | ||
return nil, errors.New("unsupported nft type") | ||
} | ||
data, err := EncodeErc721TransferFrom(sender, receiver, nftId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
gasPrice, err := c.SuggestGasPrice() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
msg := NewCallMsg() | ||
msg.SetFrom(sender) | ||
msg.SetTo(nftContractAddress) | ||
msg.SetValue("0") | ||
msg.SetGasPrice(gasPrice.Value) | ||
msg.SetData(data) | ||
|
||
gasLimit, err := c.EstimateGasLimit(msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
msg.SetGasLimit(gasLimit.Value) | ||
|
||
return msg.TransferToTransaction(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package eth | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/coming-chat/wallet-SDK/core/testcase" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestChain_TransferNFT_Erc721(t *testing.T) { | ||
mn := testcase.M1 | ||
sender, err := NewAccountWithMnemonic(mn) | ||
require.Nil(t, err) | ||
|
||
receiver := sender.Address() | ||
nftId := "0" | ||
nftContract := "0x199Dcb0132a66b05723882259832e240fF735810" | ||
nftStandard := "erc-721" | ||
|
||
chain := NewChainWithRpc("https://canary-testnet.bevm.io/") | ||
|
||
txn, err := chain.TransferNFTParams(sender.Address(), receiver, | ||
nftId, nftContract, nftStandard) | ||
require.Nil(t, err) | ||
|
||
signedTx, err := chain.BuildTransferTxWithAccount(sender, txn) | ||
require.Nil(t, err) | ||
|
||
run := false | ||
if run { | ||
txHash, err := chain.SendRawTransaction(signedTx.Value) | ||
require.Nil(t, err) | ||
t.Log(txHash) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters