import (
"math/big"
"fmt"
"time"
sdk "github.com/zkLinkProtocol/zklink_sdk/go_example/generated/uniffi/zklink_sdk"
)
func SignWithdraw() {
privateKey := "0xbe725250b123a39dab5b7579334d5888987c72a58f4508062545fe6e08ca94f4"
accountId := sdk.AccountId(8300)
subAccountId := sdk.SubAccountId(4)
toChainId := sdk.ChainId(1)
toAddress := sdk.ZkLinkAddress("0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9")
l3SourceToken := sdk.TokenId(6)
l1TargetToken := sdk.TokenId(5)
amount := *big.NewInt(1000000)
fee := *big.NewInt(1000)
nonce := sdk.Nonce(1)
withdrawFeeRatio := uint16(50)
// get current timestamp
now := time.Now()
timestamp := sdk.TimeStamp(now.Unix())
builder := sdk.WithdrawBuilder{
AccountId: accountId,
ToChainId: toChainId,
SubAccountId: subAccountId,
ToAddress: toAddress,
L2SourceToken: l3SourceToken,
L1TargetToken: l1TargetToken,
Amount: amount,
Fee: fee,
Nonce: nonce,
WithdrawToL1: true,
WithdrawFeeRatio: withdrawFeeRatio,
Timestamp: timestamp,
}
tx := sdk.NewWithdraw(builder)
signer, err := sdk.NewSigner(privateKey)
if err != nil {
return
}
txSignature, err := signer.SignWithdraw(tx, "USDT")
fmt.Println("L1 signature: %s", txSignature.Layer1Signature)
fmt.Println("signed Tx: %s", txSignature.Tx)
submitterSignature, err := signer.SubmitterSignature(txSignature.Tx)
fmt.Println("submitter signature: %s, %s", submitterSignature.PubKey, submitterSignature.Signature)
}