@@ -12,7 +12,6 @@ import (
12
12
"github.com/ethereum/go-ethereum/common/hexutil"
13
13
"github.com/ethereum/go-ethereum/core/types"
14
14
"github.com/ethereum/go-ethereum/crypto"
15
- "github.com/ethereum/go-ethereum/ethclient"
16
15
)
17
16
18
17
const TokenContractAddress = "0x.."
@@ -21,12 +20,10 @@ const SponsorPolicyId = ".."
21
20
const HotwalletPrivateKey = ".."
22
21
23
22
const sponsorAPIEndpoint = "https://open-platform.nodereal.io/{Your_API_key}/megafuel"
24
- const web3ProviderEndpoint = "https://bsc-dataseed.bnbchain.org"
25
23
const paymasterEndpoint = "https://bsc-megafuel.nodereal.io"
26
24
27
25
// testnet endpoint
28
26
// const sponsorAPIEndpoint = "https://open-platform.nodereal.io/{Your_API_key}/megafuel-testnet"
29
- // const web3ProviderEndpoint = "https://bsc-testnet-dataseed.bnbchain.org"
30
27
// const paymasterEndpoint = "https://bsc-megafuel-testnet.nodereal.io'"
31
28
32
29
func main () {
@@ -64,11 +61,6 @@ func sponsorSetUpPolicyRules() {
64
61
65
62
func cexDoGaslessWithdrawl () {
66
63
withdrawAmount := big .NewInt (1e17 )
67
- // Connect to an Ethereum node (for transaction assembly)
68
- client , err := ethclient .Dial (web3ProviderEndpoint )
69
- if err != nil {
70
- log .Fatalf ("Failed to connect to the Ethereum network: %v" , err )
71
- }
72
64
// Create a PaymasterClient (for transaction sending)
73
65
paymasterClient , err := NewPaymasterClient (paymasterEndpoint )
74
66
if err != nil {
@@ -92,8 +84,9 @@ func cexDoGaslessWithdrawl() {
92
84
log .Fatalf ("Failed to create ERC20 transfer data: %v" , err )
93
85
}
94
86
95
- // Get the latest nonce for the from address
96
- nonce , err := client .PendingNonceAt (context .Background (), fromAddress )
87
+ // Get the pending nonce for the from address, strongly suggest to fetch nonce from paymaster endpoint when
88
+ // submitting multiple transactions in rapid succession, to ensure that the nonce are sequential.
89
+ nonce , err := paymasterClient .PendingNonceAt (context .Background (), fromAddress )
97
90
if err != nil {
98
91
log .Fatalf ("Failed to get nonce: %v" , err )
99
92
}
@@ -103,7 +96,7 @@ func cexDoGaslessWithdrawl() {
103
96
tx := types .NewTransaction (nonce , tokenAddress , big .NewInt (0 ), 300000 , gasPrice , data )
104
97
105
98
// Get the chain ID
106
- chainID , err := client .ChainID (context .Background ())
99
+ chainID , err := paymasterClient .ChainID (context .Background ())
107
100
if err != nil {
108
101
log .Fatalf ("Failed to get chain ID: %v" , err )
109
102
}
0 commit comments