Upgrade Nonce
Due to 2022/06/01 Solana outage. All nonce account should be upgraded. You can update it either
- Advance Nonce (need origin authority signature)
package main
import (
"context"
"fmt"
"log"
"github.com/blocto/solana-go-sdk/client"
"github.com/blocto/solana-go-sdk/common"
"github.com/blocto/solana-go-sdk/program/system"
"github.com/blocto/solana-go-sdk/rpc"
"github.com/blocto/solana-go-sdk/types"
)
// FUarP2p5EnxD66vVDL4PWRoWMzA56ZVHG24hpEDFShEz
var feePayer, _ = types.AccountFromBase58("4TMFNY9ntAn3CHzguSAvDNLPRoQTaK3sWbQQXdDXaE6KWRBLufGL6PJdsD2koiEe3gGmMdRK3aAw7sikGNksHJrN")
// 9aE476sH92Vz7DMPyq5WLPkrKWivxeuTKEFKd2sZZcde
var alice, _ = types.AccountFromBase58("4voSPg3tYuWbKzimpQK9EbXHmuyy5fUrtXvpLDMLkmY6TRncaTHAKGD8jUg3maB5Jbrd9CkQg4qjJMyN6sQvnEF2")
func main() {
c := client.NewClient(rpc.DevnetRPCEndpoint)
// get nonce account
nonceAccountPubkey := common.PublicKeyFromString("5Covh7EB4HtC5ieeP7GwUH9AHySMmNicBmvXo534wEA8")
// recent blockhash
recentBlockhashResponse, err := c.GetLatestBlockhash(context.Background())
if err != nil {
log.Fatalf("failed to get recent blockhash, err: %v", err)
}
// create a tx
tx, err := types.NewTransaction(types.NewTransactionParam{
Signers: []types.Account{feePayer, alice},
Message: types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: recentBlockhashResponse.Blockhash,
Instructions: []types.Instruction{
system.AdvanceNonceAccount(system.AdvanceNonceAccountParam{
Nonce: nonceAccountPubkey,
Auth: alice.PublicKey,
}),
},
}),
})
if err != nil {
log.Fatalf("failed to new a transaction, err: %v", err)
}
sig, err := c.SendTransaction(context.Background(), tx)
if err != nil {
log.Fatalf("failed to send tx, err: %v", err)
}
fmt.Println("txhash", sig)
}
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
- Upgrade Nonce (you can use a random fee payer)
package main
import (
"context"
"fmt"
"log"
"github.com/blocto/solana-go-sdk/client"
"github.com/blocto/solana-go-sdk/common"
"github.com/blocto/solana-go-sdk/program/system"
"github.com/blocto/solana-go-sdk/rpc"
"github.com/blocto/solana-go-sdk/types"
)
// FUarP2p5EnxD66vVDL4PWRoWMzA56ZVHG24hpEDFShEz
var feePayer, _ = types.AccountFromBase58("4TMFNY9ntAn3CHzguSAvDNLPRoQTaK3sWbQQXdDXaE6KWRBLufGL6PJdsD2koiEe3gGmMdRK3aAw7sikGNksHJrN")
func main() {
c := client.NewClient(rpc.DevnetRPCEndpoint)
nonceAccountPubkey := common.PublicKeyFromString("DJyNpXgggw1WGgjTVzFsNjb3fuQZVMqhoakvSBfX9LYx")
// recent blockhash
recentBlockhashResponse, err := c.GetLatestBlockhash(context.Background())
if err != nil {
log.Fatalf("failed to get recent blockhash, err: %v", err)
}
tx, err := types.NewTransaction(types.NewTransactionParam{
Signers: []types.Account{feePayer},
Message: types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: recentBlockhashResponse.Blockhash,
Instructions: []types.Instruction{
system.UpgradeNonceAccount(system.UpgradeNonceAccountParam{
NonceAccountPubkey: nonceAccountPubkey,
}),
},
}),
})
if err != nil {
log.Fatalf("failed to new a transaction, err: %v", err)
}
sig, err := c.SendTransaction(context.Background(), tx)
if err != nil {
log.Fatalf("failed to send tx, err: %v", err)
}
fmt.Println("txhash", sig)
}
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
41
42
43
44
45
46
47
48
49
50
51
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
41
42
43
44
45
46
47
48
49
50
51