func Save(filepath string, cdc *codec.Codec, state interface{}) error {
	f, err := os.Create(filepath)
	if err != nil {
		return err
	}
	defer f.Close()
	jsonbytes, err := cdc.MarshalJSON(state)
	if err != nil {
		return fmt.Errorf("failed to marshal json: %s", err)
	}
	_, err = f.Write(jsonbytes)
	if err != nil {
		return err
	}
	err = f.Sync()
	if err != nil {
		return err
	}
	return nil
}
Save save the state to file, using codec json marshal.
package utils
import (
	"fmt"
	"io/ioutil"
	"os"
	"github.com/cosmos/cosmos-sdk/codec"
	sdk "github.com/cosmos/cosmos-sdk/types"
)
func Load(filepath string, cdc *codec.Codec, factory func() interface{}) (interface{}, error) {
	f, err := os.Open(filepath)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	bytes, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, err
	}
	table := factory()
	err = cdc.UnmarshalJSON(bytes, table)
	if err != nil {
		return nil, err
	}
	return table, nil
}